-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcountmin_benchmark_test.go
42 lines (37 loc) · 1.14 KB
/
countmin_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
package countmin
import (
"fmt"
"testing"
)
func Benchmark_New_1000(b *testing.B) { benchNew(b, 1000) }
func Benchmark_New_10000(b *testing.B) { benchNew(b, 10000) }
func benchNew(b *testing.B, total int) {
for i := 0; i < b.N; i++ {
New(total, total)
}
}
func Benchmark_Add_1000(b *testing.B) { benchAdd(b, 1000) }
func Benchmark_Add_10000(b *testing.B) { benchAdd(b, 10000) }
func Benchmark_Add_100000(b *testing.B) { benchAdd(b, 1000000) }
func benchAdd(b *testing.B, total int) {
cm := New(40, 200)
b.ResetTimer()
var i int64
for i = 0; i < int64(b.N); i++ {
cm.Add([]byte(fmt.Sprintf("http://domain%d.com/page%d", i, i)), i)
}
}
func Benchmark_Count_1000(b *testing.B) { benchCount(b, 1000) }
func Benchmark_Count_10000(b *testing.B) { benchCount(b, 10000) }
func Benchmark_Count_100000(b *testing.B) { benchCount(b, 1000000) }
func benchCount(b *testing.B, total int) {
cm := New(40, 200)
var i int64
for i = 0; i < int64(b.N); i++ {
cm.Add([]byte(fmt.Sprintf("http://domain%d.com/page%d", i, i)), i)
}
b.ResetTimer()
for i = 0; i < int64(b.N); i++ {
cm.Count([]byte(fmt.Sprintf("http://domain%d.com/page%d", i, i)))
}
}