util_test.go 1.01 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package util

import (
	"bytes"
	"testing"
)

func TestXOR(t *testing.T) {
	cases := [][3][]byte{
		{
			{0xFF, 0xFF, 0xFF},
			{0xFF, 0xFF, 0xFF},
			{0x00, 0x00, 0x00},
		},
		{
			{0x00, 0xFF, 0x00},
			{0xFF, 0xFF, 0xFF},
			{0xFF, 0x00, 0xFF},
		},
		{
			{0x55, 0x55, 0x55},
			{0x55, 0xFF, 0xAA},
			{0x00, 0xAA, 0xFF},
		},
	}

	for _, c := range cases {
		r := XOR(c[0], c[1])
		if !bytes.Equal(r, c[2]) {
			t.Error("XOR failed")
		}
	}
}

func BenchmarkHash256K(b *testing.B) {
	buf := make([]byte, 256*1024)
	NewTimeSeededRand().Read(buf)
	b.SetBytes(int64(256 * 1024))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Hash(buf)
	}
}

func BenchmarkHash512K(b *testing.B) {
	buf := make([]byte, 512*1024)
	NewTimeSeededRand().Read(buf)
	b.SetBytes(int64(512 * 1024))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Hash(buf)
	}
}

func BenchmarkHash1M(b *testing.B) {
	buf := make([]byte, 1024*1024)
	NewTimeSeededRand().Read(buf)
	b.SetBytes(int64(1024 * 1024))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		Hash(buf)
	}
}