From 791c58404290fb8efc71529d3daaffe93a96422a Mon Sep 17 00:00:00 2001 From: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com> Date: Sat, 14 Mar 2020 22:16:24 +0800 Subject: [PATCH] consensus: add benchmarks for mmap with/with lock --- consensus/ethash/algorithm_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go index 6182976c22..51fb6b124d 100644 --- a/consensus/ethash/algorithm_test.go +++ b/consensus/ethash/algorithm_test.go @@ -787,3 +787,28 @@ func BenchmarkHashimotoFullSmall(b *testing.B) { hashimotoFull(dataset, hash, 0) } } + +func benchmarkHashimotoFullMmap(b *testing.B, name string, lock bool) { + b.Run(name, func(b *testing.B) { + tmpdir, err := ioutil.TempDir("", "ethash-test") + if err != nil { + b.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + d := &dataset{epoch: 0} + d.generate(tmpdir, 1, lock, false) + var hash [common.HashLength]byte + b.ResetTimer() + for i := 0; i < b.N; i++ { + binary.PutVarint(hash[:], int64(i)) + hashimotoFull(d.dataset, hash[:], 0) + } + }) +} + +// Benchmarks the full verification performance for mmap +func BenchmarkHashimotoFullMmap(b *testing.B) { + benchmarkHashimotoFullMmap(b, "WithLock", true) + benchmarkHashimotoFullMmap(b, "WithoutLock", false) +}