forked from bradfitz/gitbrute
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolver_test.go
More file actions
72 lines (59 loc) · 1.79 KB
/
solver_test.go
File metadata and controls
72 lines (59 loc) · 1.79 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
66
67
68
69
70
71
72
package main
import (
"context"
"testing"
)
const testObj = `tree a9285ff39f402c54a739037ccae28d81e91bcb56
parent 029691b990bcc859f0f07036e48d2c7f8f2cb329
author Roland Illig <roland@fake.test> 1640342275 +0100
committer Brad Fitzpatrick <brad@fake.test> 1640377083 -0800
Lowercase the prefix from the command line
Previously, running gitbrute with an uppercase hex prefix had resulted
in an endless loop.
`
const testPrefix = "1234567890"
const testTS = 1641066267
var testObjBytes = []byte(testObj)
// Realistic approximation of what Solve does for benchmarking purposes,
// breaking out the check step so we can treat it as a RunParallel iteration,
// and continuing regardless of whether a match is found.
func BenchmarkSolveParallel(b *testing.B) {
ctx := context.Background()
b.RunParallel(func(pb *testing.PB) {
c := newChecker(testObjBytes, testPrefix, testTS)
genf := Explorer(0, 4)
for pb.Next() {
select {
case <-ctx.Done():
// will never happen, but want to include the select in bench
b.Fatal(ctx.Err())
default:
t := genf()
_, _ = c.check(t)
}
}
})
b.ReportMetric(float64(b.N)/b.Elapsed().Seconds(), "ops/sec")
}
// benchmark just the comparison portion, removing any overhead from candidate
// generation and worker coordination.
func BenchmarkCheck(b *testing.B) {
b.SetBytes(int64(len(testObjBytes)))
c := newChecker(testObjBytes, testPrefix, testTS)
t := try{10, 10}
for b.Loop() {
c.check(t)
}
}
// benchmark just the comparison portion, removing any overhead from candidate
// generation and worker coordination.
func BenchmarkCheckParallel(b *testing.B) {
b.SetBytes(int64(len(testObjBytes)))
b.RunParallel(func(pb *testing.PB) {
c := newChecker(testObjBytes, testPrefix, testTS)
t := try{10, 10}
for pb.Next() {
_, _ = c.check(t)
}
})
}