Skip to content

Commit 6db72c6

Browse files
authored
Merge pull request #8 from yourbasic/tip
Tip
2 parents 076b22d + e9922f3 commit 6db72c6

4 files changed

Lines changed: 624 additions & 39 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Your basic bit [![GoDoc](https://godoc.org/github.com/yourbasic/bit?status.svg)][godoc-bit]
22

3-
### Golang set data structure with bonus bit-twiddling functions
3+
### Set data structure with bonus bit-twiddling functions
44

55
A bit array, or bit set, is an efficient set data structure.
66
It consists of an array that compactly stores bits and it uses

bench_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,48 @@ import "testing"
66
const nw = 1 << 10
77

88
func BenchmarkSize(b *testing.B) {
9-
b.StopTimer()
109
s := BuildTestSet(nw << 3) // Allocates nw<<3 bytes = nw words.
11-
b.StartTimer()
12-
10+
b.ResetTimer()
1311
for i := 0; i < b.N/nw; i++ { // Measure time per word.
1412
s.Size()
1513
}
1614
}
1715

1816
func BenchmarkNext(b *testing.B) {
19-
b.StopTimer()
2017
s := BuildTestSet(b.N)
21-
b.StartTimer()
22-
18+
b.ResetTimer()
2319
for n := -2; n != -1; {
2420
n = s.Next(n)
2521
}
2622
}
2723

2824
func BenchmarkPrev(b *testing.B) {
29-
b.StopTimer()
3025
s := BuildTestSet(b.N)
31-
b.StartTimer()
32-
26+
b.ResetTimer()
3327
for n := MaxInt; n != -1; {
3428
n = s.Prev(n)
3529
}
3630
}
3731

3832
func BenchmarkVisit(b *testing.B) {
39-
b.StopTimer()
4033
s := BuildTestSet(b.N) // As Visit is pretty fast, s can be pretty big.
41-
b.StartTimer()
42-
34+
b.ResetTimer()
4335
s.Visit(func(n int) (skip bool) { return })
4436
}
4537

4638
func BenchmarkSetAnd(b *testing.B) {
47-
b.StopTimer()
4839
s := New(64*nw - 1).Delete(64*nw - 1) // Allocates nw words.
4940
s1 := BuildTestSet(nw << 3)
5041
s2 := BuildTestSet(nw << 3)
51-
b.StartTimer()
52-
42+
b.ResetTimer()
5343
for i := 0; i < b.N/nw; i++ { // Measure time per word.
5444
s.SetAnd(s1, s2)
5545
}
5646
}
5747

5848
func BenchmarkString(b *testing.B) {
59-
b.StopTimer()
6049
s := BuildTestSet(b.N) // As Visit is pretty fast, s can be pretty big.
61-
b.StartTimer()
62-
50+
b.ResetTimer()
6351
_ = s.String()
6452
}
6553

0 commit comments

Comments
 (0)