first bench 7100 op/s

This commit is contained in:
Radu Ioan Fericean
2012-02-05 12:37:40 +02:00
parent e292190958
commit 97d45d9243
3 changed files with 7 additions and 7 deletions

View File

@@ -7,6 +7,8 @@ import (
"strconv"
)
const LAYOUT = "2006-01-02T15:04:05Z07:00"
/*
The struture that is saved to storage.
*/
@@ -22,7 +24,7 @@ func (ap *ActivationPeriod) AddInterval(is ...*Interval) {
}
func (ap *ActivationPeriod) store() (result string){
result += strconv.FormatInt(ap.ActivationTime.Unix(), 10) + ";"
result += ap.ActivationTime.Format(LAYOUT) + ";"
var is string
for _,i := range ap.Intervals {
is = strconv.Itoa(int(i.Month)) + "|"
@@ -44,8 +46,7 @@ func (ap *ActivationPeriod) store() (result string){
func (ap *ActivationPeriod) restore(input string) {
elements := strings.Split(input, ";")
unix, _ := strconv.ParseInt(elements[0], 0, 64)
ap.ActivationTime = time.Unix(unix, 0)
ap.ActivationTime, _ = time.Parse(LAYOUT, elements[0])
for _, is := range elements[1:len(elements) - 1]{
i := &Interval{}
ise := strings.Split(is, "|")

View File

@@ -72,9 +72,8 @@ func TestRedisGetCost(t *testing.T) {
}
}
func TestApStoreRestore(t *testing.T) {
loc, _ := time.LoadLocation("Local")
d := time.Date(2012, time.February, 1, 14, 30, 1, 0, loc)
func TestApStoreRestore(t *testing.T) {
d := time.Date(2012, time.February, 1, 14, 30, 1, 0, time.UTC)
i := &Interval{Month: time.February,
MonthDay: 1,
WeekDays: []time.Weekday{time.Wednesday, time.Thursday},
@@ -83,7 +82,7 @@ func TestApStoreRestore(t *testing.T) {
ap := ActivationPeriod{ActivationTime: d}
ap.AddInterval(i)
result := ap.store()
expected := "1328099401;2|1|3,4|14:30:00|15:00:00|0|0|0|0;"
expected := "2012-02-01T14:30:01Z;2|1|3,4|14:30:00|15:00:00|0|0|0|0;"
if result != expected {
t.Errorf("Expected %q was %q", expected, result)
}

Binary file not shown.