-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
45 lines (36 loc) · 805 Bytes
/
benchmark_test.go
File metadata and controls
45 lines (36 loc) · 805 Bytes
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
package gophermark
import (
. "github.com/smartystreets/goconvey/convey"
"strings"
"testing"
)
func BenchmarkWithoutGopherMark(b *testing.B) {
str := strings.Repeat("I am a cat I have a hat I have a house I have a mouse!", 100)
var count int
for i := 0; i < b.N; i++ {
count = 1
b.StartTimer()
count += strings.Count(str, "mouse!")
b.StopTimer()
if count != 101 {
panic("FAIL")
}
}
}
func BenchmarkAThing(b *testing.B) {
Benchmark(b, func() {
str := strings.Repeat("I am a cat I have a hat I have a house I have a mouse!", 100)
var count int
Setup(func() {
count = 1
})
Run(func() {
count += strings.Count(str, "mouse!")
})
SanityCheck(func() {
ct := 100 + 1
Verify(str, ShouldContainSubstring, "hat")
Verify(count, ShouldEqual, ct)
})
})
}