aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2022-07-04 17:46:31 -0700
committerRon Evans <[email protected]>2022-07-05 08:54:55 +0200
commit24b1bfcecd69bdf6fda1775e6aa3fa0eb169816f (patch)
treec0868c83eb9235e80c75c401c152f04ea62ef10b /tests
parent27162ebe320088647ca6c169e91528810ab4c57f (diff)
downloadtinygo-24b1bfcecd69bdf6fda1775e6aa3fa0eb169816f.tar.gz
tinygo-24b1bfcecd69bdf6fda1775e6aa3fa0eb169816f.zip
tests/runtime: add benchmarks for runtime memhash
Diffstat (limited to 'tests')
-rw-r--r--tests/runtime/memhash_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/runtime/memhash_test.go b/tests/runtime/memhash_test.go
new file mode 100644
index 000000000..081520ed7
--- /dev/null
+++ b/tests/runtime/memhash_test.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "hash/maphash"
+ "strconv"
+ "testing"
+)
+
+var buf [8192]byte
+
+func BenchmarkMaphash(b *testing.B) {
+ var h maphash.Hash
+ benchmarkHash(b, "maphash", h)
+}
+
+func benchmarkHash(b *testing.B, str string, h maphash.Hash) {
+ var sizes = []int{1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1024, 8192}
+ for _, n := range sizes {
+ b.Run(strconv.Itoa(n), func(b *testing.B) { benchmarkHashn(b, int64(n), h) })
+ }
+}
+
+var total uint64
+
+func benchmarkHashn(b *testing.B, size int64, h maphash.Hash) {
+ b.SetBytes(size)
+
+ sum := make([]byte, 4)
+
+ for i := 0; i < b.N; i++ {
+ h.Reset()
+ h.Write(buf[:size])
+ sum = h.Sum(sum[:0])
+ total += uint64(sum[0])
+ }
+}