-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_benchmark_test.go
More file actions
57 lines (43 loc) · 1.25 KB
/
queue_benchmark_test.go
File metadata and controls
57 lines (43 loc) · 1.25 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
package queue
import (
"crypto/rand"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func benchmarkEnqueue(b *testing.B, value []byte) {
f, err := ioutil.TempFile("", "test-*")
assert := assert.New(b)
assert.Nil(err)
q := NewQueue(f)
b.ResetTimer()
for n := 0; n < b.N; n++ {
q.Enqueue(value)
}
}
func BenchmarkEnqueue5(b *testing.B) { benchmarkEnqueue(b, nBytes(5)) }
func BenchmarkEnqueue10(b *testing.B) { benchmarkEnqueue(b, nBytes(10)) }
func BenchmarkEnqueue50(b *testing.B) { benchmarkEnqueue(b, nBytes(50)) }
func BenchmarkEnqueue100(b *testing.B) { benchmarkEnqueue(b, nBytes(100)) }
func benchmarkDequeue(b *testing.B, value []byte) {
f, err := ioutil.TempFile("", "test-*")
assert := assert.New(b)
assert.Nil(err)
q := NewQueue(f)
for n := 0; n < b.N; n++ {
q.Enqueue(value)
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
q.Dequeue()
}
}
func BenchmarkDequeue5(b *testing.B) { benchmarkEnqueue(b, nBytes(5)) }
func BenchmarkDequeue10(b *testing.B) { benchmarkEnqueue(b, nBytes(10)) }
func BenchmarkDequeue50(b *testing.B) { benchmarkEnqueue(b, nBytes(50)) }
func BenchmarkDequeue100(b *testing.B) { benchmarkEnqueue(b, nBytes(100)) }
func nBytes(n int) []byte {
bs := make([]byte, n)
rand.Read(bs)
return bs
}