Skip to content

Commit

Permalink
benchmark Get
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Apr 28, 2024
1 parent bbf63a6 commit 785aa9d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions ast/raw_test.go
Expand Up @@ -823,3 +823,45 @@ func BenchmarkNodesGetByPath_NewNode(b *testing.B) {
}
})
}

func getSample(width int, depth int) string {
obj := map[string]interface{}{}
for i := 0; i < width; i++ {
var v interface{}
if depth > 0 {
v = json.RawMessage(getSample(width/2+1, depth-1))
} else {
v = 1
}
obj[strconv.Itoa(i)] = v
}
js, _ := json.Marshal(obj)
return string(js)
}

func BenchmarkValue_GetByPath(b *testing.B) {
b.Run("10/2", func(b *testing.B) {
src := getSample(10, 0)
n := NewValueJSON(src)
b.ResetTimer()
for i:=0; i<b.N; i++ {
_ = n.GetByPath("5")
}
})
b.Run("100/2", func(b *testing.B) {
src := getSample(100, 0)
n := NewValueJSON(src)
b.ResetTimer()
for i:=0; i<b.N; i++ {
_ = n.GetByPath("50")
}
})
b.Run("1000/2", func(b *testing.B) {
src := getSample(1000, 0)
n := NewValueJSON(src)
b.ResetTimer()
for i:=0; i<b.N; i++ {
_ = n.GetByPath("500")
}
})
}
2 changes: 1 addition & 1 deletion tools/simde
Submodule simde updated from 4d55fc to 416091

0 comments on commit 785aa9d

Please sign in to comment.