Skip to content

Commit 067dc39

Browse files
inkelsbarzowski
authored andcommitted
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 <[email protected]>
1 parent 63a4522 commit 067dc39

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

ast/util_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package ast
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func testIdentifiers(n int) Identifiers {
9+
var is []Identifier
10+
for i := 0; i < n; i++ {
11+
is = append(is, Identifier(fmt.Sprintf("id-%06d", i)))
12+
}
13+
return Identifiers(is)
14+
}
15+
16+
var results []Identifier
17+
18+
func BenchmarkToOrderedSlice(b *testing.B) {
19+
tests := []Identifiers{
20+
testIdentifiers(1),
21+
testIdentifiers(10),
22+
testIdentifiers(100),
23+
testIdentifiers(1000),
24+
testIdentifiers(10000),
25+
testIdentifiers(100000),
26+
}
27+
28+
for _, t := range tests {
29+
is := IdentifierSet{}
30+
is.AddIdentifiers(t)
31+
32+
b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) {
33+
var r []Identifier
34+
for i := 0; i < b.N; i++ {
35+
r = is.ToOrderedSlice()
36+
}
37+
results = r
38+
})
39+
}
40+
}
41+
42+
func BenchmarkToSlice(b *testing.B) {
43+
tests := []Identifiers{
44+
testIdentifiers(1),
45+
testIdentifiers(10),
46+
testIdentifiers(100),
47+
testIdentifiers(1000),
48+
testIdentifiers(10000),
49+
testIdentifiers(100000),
50+
}
51+
52+
for _, t := range tests {
53+
is := IdentifierSet{}
54+
is.AddIdentifiers(t)
55+
56+
b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) {
57+
var r []Identifier
58+
for i := 0; i < b.N; i++ {
59+
r = is.ToSlice()
60+
}
61+
results = r
62+
})
63+
}
64+
}

0 commit comments

Comments
 (0)