mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-10 00:07:13 +02:00
Add IdentifierSet.ToOrderedSlice and ToSlice benchmarks
This will be useful later on when implementing the performance improvements to compare how much we gain. Signed-off-by: Leandro López <leandro.lopez@grafana.com>
This commit is contained in:
parent
63a452246d
commit
067dc391aa
64
ast/util_test.go
Normal file
64
ast/util_test.go
Normal file
@ -0,0 +1,64 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testIdentifiers(n int) Identifiers {
|
||||
var is []Identifier
|
||||
for i := 0; i < n; i++ {
|
||||
is = append(is, Identifier(fmt.Sprintf("id-%06d", i)))
|
||||
}
|
||||
return Identifiers(is)
|
||||
}
|
||||
|
||||
var results []Identifier
|
||||
|
||||
func BenchmarkToOrderedSlice(b *testing.B) {
|
||||
tests := []Identifiers{
|
||||
testIdentifiers(1),
|
||||
testIdentifiers(10),
|
||||
testIdentifiers(100),
|
||||
testIdentifiers(1000),
|
||||
testIdentifiers(10000),
|
||||
testIdentifiers(100000),
|
||||
}
|
||||
|
||||
for _, t := range tests {
|
||||
is := IdentifierSet{}
|
||||
is.AddIdentifiers(t)
|
||||
|
||||
b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) {
|
||||
var r []Identifier
|
||||
for i := 0; i < b.N; i++ {
|
||||
r = is.ToOrderedSlice()
|
||||
}
|
||||
results = r
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkToSlice(b *testing.B) {
|
||||
tests := []Identifiers{
|
||||
testIdentifiers(1),
|
||||
testIdentifiers(10),
|
||||
testIdentifiers(100),
|
||||
testIdentifiers(1000),
|
||||
testIdentifiers(10000),
|
||||
testIdentifiers(100000),
|
||||
}
|
||||
|
||||
for _, t := range tests {
|
||||
is := IdentifierSet{}
|
||||
is.AddIdentifiers(t)
|
||||
|
||||
b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) {
|
||||
var r []Identifier
|
||||
for i := 0; i < b.N; i++ {
|
||||
r = is.ToSlice()
|
||||
}
|
||||
results = r
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user