v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/hash/memhash_test.go (about) 1 package hash 2 3 import ( 4 "crypto/rand" 5 "testing" 6 ) 7 8 const seed = 42 9 10 func BenchmarkMemhash128(b *testing.B) { 11 data := make([]byte, 128) 12 rand.Read(data) 13 b.SetBytes(int64(len(data))) 14 b.RunParallel(func(p *testing.PB) { 15 for p.Next() { 16 MemHash(data, seed) 17 } 18 }) 19 } 20 21 func BenchmarkMemhash256(b *testing.B) { 22 data := make([]byte, 256) 23 rand.Read(data) 24 b.SetBytes(int64(len(data))) 25 b.RunParallel(func(p *testing.PB) { 26 for p.Next() { 27 MemHash(data, seed) 28 } 29 }) 30 } 31 32 func BenchmarkMemhash512(b *testing.B) { 33 data := make([]byte, 512) 34 rand.Read(data) 35 b.SetBytes(int64(len(data))) 36 b.RunParallel(func(p *testing.PB) { 37 for p.Next() { 38 MemHash(data, seed) 39 } 40 }) 41 } 42 43 func BenchmarkMemhash1024(b *testing.B) { 44 data := make([]byte, 1024) 45 rand.Read(data) 46 b.SetBytes(int64(len(data))) 47 b.RunParallel(func(p *testing.PB) { 48 for p.Next() { 49 MemHash(data, seed) 50 } 51 }) 52 } 53 54 func BenchmarkMemhash2048(b *testing.B) { 55 data := make([]byte, 2048) 56 rand.Read(data) 57 b.SetBytes(int64(len(data))) 58 b.RunParallel(func(p *testing.PB) { 59 for p.Next() { 60 MemHash(data, seed) 61 } 62 }) 63 } 64 65 func BenchmarkMemhash4096(b *testing.B) { 66 data := make([]byte, 4096) 67 rand.Read(data) 68 b.SetBytes(int64(len(data))) 69 b.RunParallel(func(p *testing.PB) { 70 for p.Next() { 71 MemHash(data, seed) 72 } 73 }) 74 } 75 76 func BenchmarkMemhash8192(b *testing.B) { 77 data := make([]byte, 8192) 78 rand.Read(data) 79 b.SetBytes(int64(len(data))) 80 b.RunParallel(func(p *testing.PB) { 81 for p.Next() { 82 MemHash(data, seed) 83 } 84 }) 85 } 86 87 func BenchmarkMemhash16384(b *testing.B) { 88 data := make([]byte, 16384) 89 rand.Read(data) 90 b.SetBytes(int64(len(data))) 91 b.RunParallel(func(p *testing.PB) { 92 for p.Next() { 93 MemHash(data, seed) 94 } 95 }) 96 } 97 98 func BenchmarkMemhash32768(b *testing.B) { 99 data := make([]byte, 32768) 100 rand.Read(data) 101 b.SetBytes(int64(len(data))) 102 b.RunParallel(func(p *testing.PB) { 103 for p.Next() { 104 MemHash(data, seed) 105 } 106 }) 107 } 108 109 func BenchmarkMemhash65536(b *testing.B) { 110 data := make([]byte, 65536) 111 rand.Read(data) 112 b.SetBytes(int64(len(data))) 113 b.RunParallel(func(p *testing.PB) { 114 for p.Next() { 115 MemHash(data, seed) 116 } 117 }) 118 } 119 120 func BenchmarkMemhash131072(b *testing.B) { 121 data := make([]byte, 131072) 122 rand.Read(data) 123 b.SetBytes(int64(len(data))) 124 b.RunParallel(func(p *testing.PB) { 125 for p.Next() { 126 MemHash(data, seed) 127 } 128 }) 129 }