aboutsummaryrefslogtreecommitdiff
path: root/internal/cryptocore/randsize_test.go
blob: 1db4745644bd485b6f96dfde8bae6878e99598fb (plain)
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
// +build go1.7

// ^^^^^^^^^^^^ we use the "sub-benchmark" feature that was added in Go 1.7

package cryptocore

import (
	"fmt"
	"testing"
)

/*
The troughput we get from /dev/urandom / getentropy depends a lot on the used
block size. Results on my Pentium G630 running Linux 4.11:

BenchmarkRandSize/16-2         	 3000000	       571 ns/op	  27.98 MB/s
BenchmarkRandSize/32-2         	 3000000	       585 ns/op	  54.66 MB/s
BenchmarkRandSize/64-2         	 2000000	       860 ns/op	  74.36 MB/s
BenchmarkRandSize/128-2        	 1000000	      1197 ns/op	 106.90 MB/s
BenchmarkRandSize/256-2        	 1000000	      1867 ns/op	 137.06 MB/s
BenchmarkRandSize/512-2        	  500000	      3187 ns/op	 160.61 MB/s
BenchmarkRandSize/1024-2       	  200000	      5888 ns/op	 173.91 MB/s
BenchmarkRandSize/2048-2       	  100000	     11554 ns/op	 177.25 MB/s
BenchmarkRandSize/4096-2       	  100000	     22523 ns/op	 181.86 MB/s
BenchmarkRandSize/8192-2       	   30000	     43111 ns/op	 190.02 MB/s

Results are similar when testing with dd, so this is not due to Go allocation
overhead: dd if=/dev/urandom bs=16 count=100000 of=/dev/null
*/
func BenchmarkUrandomBlocksize(b *testing.B) {
	for s := 16; s <= 8192; s *= 2 {
		title := fmt.Sprintf("%d", s)
		b.Run(title, func(b *testing.B) {
			b.SetBytes(int64(s))
			for i := 0; i < b.N; i++ {
				RandBytes(s)
			}
		})
	}
}