Skip to content

Commit 0127683

Browse files
authored
Merge pull request #5 from globocom/add-benchmark-tests
Add benchmark tests
2 parents 9b86919 + a7cc02b commit 0127683

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
test:
2-
@go run github.com/onsi/ginkgo/ginkgo -keepGoing -progress -timeout 1m -race --randomizeAllSpecs --randomizeSuites
2+
go run github.com/onsi/ginkgo/ginkgo -keepGoing -progress -timeout 1m -race --randomizeAllSpecs --randomizeSuites
3+
4+
bench:
5+
go test -bench=. -run=Benchmark

bench_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package buffer_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/globocom/go-buffer"
7+
)
8+
9+
func BenchmarkBuffer(b *testing.B) {
10+
noop := buffer.FlusherFunc(func([]interface{}) {})
11+
12+
b.Run("push only", func(b *testing.B) {
13+
sut := buffer.New(
14+
buffer.WithSize(uint(b.N)+1),
15+
buffer.WithFlusher(noop),
16+
)
17+
defer sut.Close()
18+
19+
for i := 0; i < b.N; i++ {
20+
err := sut.Push(i)
21+
if err != nil {
22+
b.Fail()
23+
}
24+
}
25+
})
26+
27+
b.Run("push and flush", func(b *testing.B) {
28+
sut := buffer.New(
29+
buffer.WithSize(1),
30+
buffer.WithFlusher(noop),
31+
)
32+
defer sut.Close()
33+
34+
for i := 0; i < b.N; i++ {
35+
err := sut.Push(i)
36+
if err != nil {
37+
b.Fail()
38+
}
39+
}
40+
})
41+
}

0 commit comments

Comments
 (0)