-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbench_test.go
More file actions
65 lines (50 loc) · 1.32 KB
/
bench_test.go
File metadata and controls
65 lines (50 loc) · 1.32 KB
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
58
59
60
61
62
63
64
65
package hrw
import "testing"
func BenchmarkSort_fnv_10(b *testing.B) {
_ = benchmarkSort(b, 10, testKey)
}
func BenchmarkSort_fnv_100(b *testing.B) {
_ = benchmarkSort(b, 100, testKey)
}
func BenchmarkSort_fnv_1000(b *testing.B) {
_ = benchmarkSort(b, 1000, testKey)
}
func BenchmarkSortByWeight_fnv_10(b *testing.B) {
_ = benchmarkSortByWeight(b, 10, testKey)
}
func BenchmarkSortByWeight_fnv_100(b *testing.B) {
_ = benchmarkSortByWeight(b, 100, testKey)
}
func BenchmarkSortByWeight_fnv_1000(b *testing.B) {
_ = benchmarkSortByWeight(b, 1000, testKey)
}
func benchmarkSort(b *testing.B, n int, object []byte) uint64 {
servers := make([]hashableUint64, n)
for i := range servers {
servers[i] = hashableUint64(uint64(i))
}
oHash := hashableUint64(WrapBytes(object).Hash())
b.ReportAllocs()
var x uint64
for b.Loop() {
Sort(servers, oHash)
x += servers[0].Hash()
}
return x
}
func benchmarkSortByWeight(b *testing.B, n int, object []byte) uint64 {
servers := make([]hashableUint64, n)
weights := make([]float64, n)
for i := range servers {
weights[i] = float64(uint64(n-i)) / float64(n)
servers[i] = hashableUint64(uint64(i))
}
oHash := hashableUint64(WrapBytes(object).Hash())
b.ReportAllocs()
var x uint64
for b.Loop() {
SortWeighted(servers, weights, oHash)
x += servers[0].Hash()
}
return x
}