-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark_test.go
50 lines (40 loc) · 984 Bytes
/
benchmark_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
package dot_test
import (
"github.com/mowshon/dot"
"testing"
)
type Inner struct {
Field string
}
type Nested struct {
MapField map[string]Inner
SliceField []Inner
StructField Inner
ArrayField [1]Inner
}
func BenchmarkDotInsert(b *testing.B) {
data := Nested{}
data.MapField = make(map[string]Inner)
data.SliceField = make([]Inner, 1)
obj, _ := dot.New(&data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
obj.Insert("MapField.key.Field", "My Value")
obj.Insert("SliceField.0.Field", "My Value")
obj.Insert("StructField.Field", "My Value")
obj.Insert("ArrayField.0.Field", "My Value")
}
}
func BenchmarkNativeInsert(b *testing.B) {
data := Nested{}
data.MapField = make(map[string]Inner)
data.SliceField = make([]Inner, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
add, _ := data.MapField["key"]
add.Field = "My Value"
data.SliceField[0].Field = "My Value"
data.StructField.Field = "My Value"
data.ArrayField[0].Field = "My Value"
}
}