randbo_test.go 603 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
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
package randbo

import (
	"crypto/rand"
	"io"
	"io/ioutil"
	"testing"
)

func TestRandbo(t *testing.T) {
	buf := make([]byte, 16)
	n, err := New().Read(buf)
	if err != nil {
		t.Fatalf("Error reading: %v", err)
	}
	if n != len(buf) {
		t.Fatalf("Short read: %v", n)
	}
	t.Logf("Read %x", buf)
}

const toCopy = 1024 * 1024

func BenchmarkRandbo(b *testing.B) {
	b.SetBytes(toCopy)
	r := New()
	for i := 0; i < b.N; i++ {
		io.CopyN(ioutil.Discard, r, toCopy)
	}
}

func BenchmarkCrypto(b *testing.B) {
	b.SetBytes(toCopy)
	for i := 0; i < b.N; i++ {
		io.CopyN(ioutil.Discard, rand.Reader, toCopy)
	}
}