-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renamed hex trie * implemented insert for binary hex trie * added retrieve for binary trie * added delete for binary trie * added hashing to binary trie * added tests for binary trie * improved test output * fixed bitset/slice shenanigans * added benchmark for hex & bin tries * added benchmark for hashing closes #125
- Loading branch information
Max Wolter
committed
Mar 14, 2018
1 parent
daca31d
commit 6607743
Showing
9 changed files
with
682 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
// Copyright (c) 2017 The Alvalor Authors | ||
// | ||
// This file is part of Alvalor. | ||
// | ||
// Alvalor is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Alvalor is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with Alvalor. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package trie | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
) | ||
|
||
func BenchmarkBinInsert(b *testing.B) { | ||
t := NewBin() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
} | ||
|
||
func BenchmarkBinRetrieve(b *testing.B) { | ||
t := NewBin() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Get(keys[i]) | ||
} | ||
} | ||
|
||
func BenchmarkBinDelete(b *testing.B) { | ||
t := NewBin() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Del(keys[i]) | ||
} | ||
} | ||
|
||
func BenchmarkBinHash(b *testing.B) { | ||
t := NewBin() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Hash() | ||
} | ||
} | ||
|
||
func BenchmarkHexInsert(b *testing.B) { | ||
t := NewHex() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
} | ||
|
||
func BenchmarkHexRetrieve(b *testing.B) { | ||
t := NewHex() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Get(keys[i]) | ||
} | ||
} | ||
|
||
func BenchmarkHexDelete(b *testing.B) { | ||
t := NewHex() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Del(keys[i]) | ||
} | ||
} | ||
|
||
func BenchmarkHexHash(b *testing.B) { | ||
t := NewHex() | ||
keys := make([][]byte, 0, b.N) | ||
hashes := make([][]byte, 0, b.N) | ||
for i := 0; i < b.N; i++ { | ||
key := make([]byte, 32) | ||
hash := make([]byte, 32) | ||
_, _ = rand.Read(key) | ||
_, _ = rand.Read(hash) | ||
keys = append(keys, key) | ||
hashes = append(hashes, hash) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
t.MustPut(keys[i], hashes[i]) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
t.Hash() | ||
} | ||
} |
Oops, something went wrong.