14 {0x00000000, 0x0000000000000000, 0x0000000000000000, ""},
15 {0x248bfa47, 0xcbd8a7b341bd9b02, 0x5b1e906a48ae1d19, "hello"},
16 {0x149bbb7f, 0x342fac623a5ebc8e, 0x4cdcbc079642414d, "hello, world"},
17 {0xe31e8a70, 0xb89e5988b737affc, 0x664fc2950231b2cb, "19 Jan 2038 at 3:14:07 AM"},
18 {0xd5c48bfc, 0xcd99481f9ee902c9, 0x695da1a38987b6e7, "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 if v := Sum64([]byte(elem.s)); v != elem.h64_1 {
41 t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
44 var h128 Hash128 = New128()
45 h128.Write([]byte(elem.s))
46 if v1, v2 := h128.Sum128(); 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)
50 if v1, v2 := Sum128([]byte(elem.s)); v1 != elem.h64_1 || v2 != elem.h64_2 {
51 t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
56 func TestIncremental(t *testing.T) {
57 for _, elem := range data {
60 for i, j, k := 0, 0, len(elem.s); i < k; i = j {
71 if v := h32.Sum32(); v != elem.h32 {
72 t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
74 if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
75 t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
82 func bench32(b *testing.B, length int) {
83 buf := make([]byte, length)
84 b.SetBytes(int64(length))
86 for i := 0; i < b.N; i++ {
91 func Benchmark32_1(b *testing.B) {
94 func Benchmark32_2(b *testing.B) {
97 func Benchmark32_4(b *testing.B) {
100 func Benchmark32_8(b *testing.B) {
103 func Benchmark32_16(b *testing.B) {
106 func Benchmark32_32(b *testing.B) {
109 func Benchmark32_64(b *testing.B) {
112 func Benchmark32_128(b *testing.B) {
115 func Benchmark32_256(b *testing.B) {
118 func Benchmark32_512(b *testing.B) {
121 func Benchmark32_1024(b *testing.B) {
124 func Benchmark32_2048(b *testing.B) {
127 func Benchmark32_4096(b *testing.B) {
130 func Benchmark32_8192(b *testing.B) {
136 func benchPartial32(b *testing.B, length int) {
137 buf := make([]byte, length)
138 b.SetBytes(int64(length))
140 start := (32 / 8) / 2
143 tail := (length - start) % k
146 for i := 0; i < b.N; i++ {
148 hasher.Write(buf[0:start])
150 for j := start; j+k <= length; j += k {
151 hasher.Write(buf[j : j+k])
154 hasher.Write(buf[length-tail:])
159 func BenchmarkPartial32_8(b *testing.B) {
162 func BenchmarkPartial32_16(b *testing.B) {
163 benchPartial32(b, 16)
165 func BenchmarkPartial32_32(b *testing.B) {
166 benchPartial32(b, 32)
168 func BenchmarkPartial32_64(b *testing.B) {
169 benchPartial32(b, 64)
171 func BenchmarkPartial32_128(b *testing.B) {
172 benchPartial32(b, 128)
177 func bench128(b *testing.B, length int) {
178 buf := make([]byte, length)
179 b.SetBytes(int64(length))
181 for i := 0; i < b.N; i++ {
186 func Benchmark128_1(b *testing.B) {
189 func Benchmark128_2(b *testing.B) {
192 func Benchmark128_4(b *testing.B) {
195 func Benchmark128_8(b *testing.B) {
198 func Benchmark128_16(b *testing.B) {
201 func Benchmark128_32(b *testing.B) {
204 func Benchmark128_64(b *testing.B) {
207 func Benchmark128_128(b *testing.B) {
210 func Benchmark128_256(b *testing.B) {
213 func Benchmark128_512(b *testing.B) {
216 func Benchmark128_1024(b *testing.B) {
219 func Benchmark128_2048(b *testing.B) {
222 func Benchmark128_4096(b *testing.B) {
225 func Benchmark128_8192(b *testing.B) {