-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
57 lines (50 loc) · 1.04 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dynago_test
import (
"testing"
"github.com/twharmon/dynago"
)
// BenchmarkMarshall-10 1279446 924.3 ns/op 867 B/op 10 allocs/op
// BenchmarkUnmarshall-10 1500501 801.1 ns/op 254 B/op 6 allocs/op
func BenchmarkMarshall(b *testing.B) {
ddb := mock(b)
client := dynago.New(ddb)
type Person struct {
*CompositeTable
Name string `attr:"PK" fmt:"Person#{}"`
Age int64
}
person := Person{
Name: "Gopher",
Age: 14,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := client.Marshal(person); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkUnmarshall(b *testing.B) {
ddb := mock(b)
client := dynago.New(ddb)
type Person struct {
*CompositeTable
Name string `attr:"PK" fmt:"Person#{}"`
Age int64
}
person := Person{
Name: "Gopher",
Age: 14,
}
av, err := client.Marshal(person)
if err != nil {
b.Fatal(err)
}
var output Person
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := client.Unmarshal(av, &output); err != nil {
b.Fatal(err)
}
}
}