-
Notifications
You must be signed in to change notification settings - Fork 0
/
thru_bench_test.go
48 lines (39 loc) · 1.1 KB
/
thru_bench_test.go
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
// chris 061515 Throughput benchmark testing.
package steg
import (
"bytes"
"testing"
"crypto/rand"
"io/ioutil"
)
// benchSize is the number of bytes in the carrier for a benchmarking
// test.
const benchSize = 3 * 1000 * 1000
func benchmarkSetup(b *testing.B, atomSize uint8) (ctx *Ctx, carrierBytes, msgBytes []byte) {
ctx = NewCtx(atomSize)
carrierBytes = make([]byte, benchSize)
if _, err := rand.Read(carrierBytes); err != nil {
b.Error(err)
return
}
capacity := ctx.Capacity(benchSize)
msgBytes = make([]byte, capacity)
if _, err := rand.Read(msgBytes); err != nil {
b.Error(err)
return
}
return ctx, carrierBytes, msgBytes
}
func benchmarkN(b *testing.B, atomSize uint8) {
ctx, carrierBytes, msgBytes := benchmarkSetup(b, atomSize)
b.ResetTimer()
for i := 0; i < b.N; i++ {
carrier := bytes.NewBuffer(carrierBytes)
msg := bytes.NewBuffer(msgBytes)
ctx.NewMux(ioutil.Discard, carrier, msg).Mux()
}
}
// Benchmark by atom size.
func Benchmark1(b *testing.B) { benchmarkN(b, 1) }
func Benchmark2(b *testing.B) { benchmarkN(b, 2) }
func Benchmark3(b *testing.B) { benchmarkN(b, 3) }