14
{0x514e28b7, 0x4610abe56eff5cb5, 0x51622daa78f83583, ""},
15
{0xbb4abcad, 0xa78ddff5adae8d10, 0x128900ef20900135, "hello"},
16
{0x6f5cb2e9, 0x8b95f808840725c6, 0x1597ed5422bd493b, "hello, world"},
17
{0xf50e1f30, 0x2a929de9c8f97b2f, 0x56a41d99af43a2db, "19 Jan 2038 at 3:14:07 AM"},
18
{0x846f6a36, 0xfb3325171f9744da, 0xaaf8b92a5f722952, "The quick brown fox jumps over the lazy dog."},
21
func TestRef(t *testing.T) {
22
for _, elem := range data {
24
var h32 hash.Hash32 = New32()
25
h32.Write([]byte(elem.s))
26
if v := h32.Sum32(); v != elem.h32 {
27
t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
30
if v := Sum32([]byte(elem.s)); v != elem.h32 {
31
t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
34
var h64 hash.Hash64 = New64()
35
h64.Write([]byte(elem.s))
36
if v := h64.Sum64(); v != elem.h64_1 {
37
t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
40
var h128 Hash128 = New128()
41
h128.Write([]byte(elem.s))
42
if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
43
t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
46
if v1, v2 := Sum128([]byte(elem.s)); v1 != elem.h64_1 || v2 != elem.h64_2 {
47
t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
52
func TestIncremental(t *testing.T) {
53
for _, elem := range data {
56
for i, j, k := 0, 0, len(elem.s); i < k; i = j {
67
if v := h32.Sum32(); v != elem.h32 {
68
t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
70
if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
71
t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
78
func bench32(b *testing.B, length int) {
79
buf := make([]byte, length)
80
b.SetBytes(int64(length))
82
for i := 0; i < b.N; i++ {
87
func Benchmark32_1(b *testing.B) {
90
func Benchmark32_2(b *testing.B) {
93
func Benchmark32_4(b *testing.B) {
96
func Benchmark32_8(b *testing.B) {
99
func Benchmark32_16(b *testing.B) {
102
func Benchmark32_32(b *testing.B) {
105
func Benchmark32_64(b *testing.B) {
108
func Benchmark32_128(b *testing.B) {
111
func Benchmark32_256(b *testing.B) {
114
func Benchmark32_512(b *testing.B) {
117
func Benchmark32_1024(b *testing.B) {
120
func Benchmark32_2048(b *testing.B) {
123
func Benchmark32_4096(b *testing.B) {
126
func Benchmark32_8192(b *testing.B) {
132
func benchPartial32(b *testing.B, length int) {
133
buf := make([]byte, length)
134
b.SetBytes(int64(length))
136
start := (32 / 8) / 2
139
tail := (length - start) % k
142
for i := 0; i < b.N; i++ {
144
hasher.Write(buf[0:start])
146
for j := start; j+k <= length; j += k {
147
hasher.Write(buf[j : j+k])
150
hasher.Write(buf[length-tail:])
155
func BenchmarkPartial32_8(b *testing.B) {
158
func BenchmarkPartial32_16(b *testing.B) {
159
benchPartial32(b, 16)
161
func BenchmarkPartial32_32(b *testing.B) {
162
benchPartial32(b, 32)
164
func BenchmarkPartial32_64(b *testing.B) {
165
benchPartial32(b, 64)
167
func BenchmarkPartial32_128(b *testing.B) {
168
benchPartial32(b, 128)
173
func bench128(b *testing.B, length int) {
174
buf := make([]byte, length)
175
b.SetBytes(int64(length))
177
for i := 0; i < b.N; i++ {
182
func Benchmark128_1(b *testing.B) {
185
func Benchmark128_2(b *testing.B) {
188
func Benchmark128_4(b *testing.B) {
191
func Benchmark128_8(b *testing.B) {
194
func Benchmark128_16(b *testing.B) {
197
func Benchmark128_32(b *testing.B) {
200
func Benchmark128_64(b *testing.B) {
203
func Benchmark128_128(b *testing.B) {
206
func Benchmark128_256(b *testing.B) {
209
func Benchmark128_512(b *testing.B) {
212
func Benchmark128_1024(b *testing.B) {
215
func Benchmark128_2048(b *testing.B) {
218
func Benchmark128_4096(b *testing.B) {
221
func Benchmark128_8192(b *testing.B) {