-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks_test.go
57 lines (47 loc) · 1.68 KB
/
benchmarks_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 wordpatterns_test
import (
"testing"
. "github.com/mrap/wordpatterns"
)
const (
list100 = "test/100_test_words.txt"
list1000 = "test/1000_test_words.txt"
list10000 = "test/10000_test_words.txt"
listGoogle10000 = "test/google-10000-english.txt"
)
func buildTrie(filename string, b *testing.B) {
for i := 0; i < b.N; i++ {
CreateTrie(filename)
}
}
func buildWordmap(filename string, b *testing.B) {
for i := 0; i < b.N; i++ {
wm := NewWordmap(&WordmapOptions{MinSubstrLen: 2})
PopulateFromFile(wm, filename)
}
}
func BenchmarkBuildTrie100(b *testing.B) { buildTrie(list100, b) }
func BenchmarkBuildTrie1000(b *testing.B) { buildTrie(list1000, b) }
func BenchmarkBuildTrie10000(b *testing.B) { buildTrie(list10000, b) }
func BenchmarkBuildTrieGoogle10000(b *testing.B) { buildTrie(listGoogle10000, b) }
func BenchmarkBuildWordmap100(b *testing.B) { buildWordmap(list100, b) }
func BenchmarkBuildWordmap1000(b *testing.B) { buildWordmap(list1000, b) }
func BenchmarkBuildWordmap10000(b *testing.B) { buildWordmap(list10000, b) }
func BenchmarkBuildWordmapGoogle10000(b *testing.B) { buildWordmap(listGoogle10000, b) }
func trieQuery(query string, b *testing.B) {
trie := CreateTrie(list1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
trie.WordsContaining(query)
}
}
func wordmapQuery(query string, b *testing.B) {
wm := NewWordmap(&WordmapOptions{MinSubstrLen: 2})
PopulateFromFile(wm, list1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
wm.WordsContaining(query)
}
}
func BenchmarkTrieQueryEr(b *testing.B) { trieQuery("er", b) }
func BenchmarkWordmapQueryEr(b *testing.B) { wordmapQuery("er", b) }