diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-18 19:03:09 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-18 19:03:09 +0800 |
commit | 3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9 (patch) | |
tree | 695f0462fb1fb080417b7e18874986847103a37e /trie/trie_test.go | |
parent | f7417d3552de86f5acf969b6eb882502fd104a11 (diff) | |
download | dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar.gz dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar.bz2 dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar.lz dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar.xz dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.tar.zst dexon-3220a32ff056f5bffed031bf1c4d3b0bc71f1ec9.zip |
Added some comparison tests for the new ptrie
Diffstat (limited to 'trie/trie_test.go')
-rw-r--r-- | trie/trie_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/trie/trie_test.go b/trie/trie_test.go index 4c7e621dc..d00671c6a 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -444,3 +444,59 @@ func TestRndCase(t *testing.T) { fmt.Printf("%x\n", trie.Get(string(ethutil.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")))) } */ + +func TestOtherSomething(t *testing.T) { + _, trie := NewTrie() + + vals := []struct{ k, v string }{ + {"do", "verb"}, + {"ether", "wookiedoo"}, + {"horse", "stallion"}, + {"shaman", "horse"}, + {"doge", "coin"}, + {"ether", ""}, + {"dog", "puppy"}, + {"shaman", ""}, + } + for _, val := range vals { + trie.Update(val.k, val.v) + } + + exp := ethutil.Hex2Bytes("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84") + hash := trie.Root.([]byte) + if !bytes.Equal(hash, exp) { + t.Errorf("expected %x got %x", exp, hash) + } +} + +func BenchmarkGets(b *testing.B) { + _, trie := NewTrie() + vals := []struct{ k, v string }{ + {"do", "verb"}, + {"ether", "wookiedoo"}, + {"horse", "stallion"}, + {"shaman", "horse"}, + {"doge", "coin"}, + {"ether", ""}, + {"dog", "puppy"}, + {"shaman", ""}, + {"somethingveryoddindeedthis is", "myothernodedata"}, + } + for _, val := range vals { + trie.Update(val.k, val.v) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + trie.Get("horse") + } +} + +func BenchmarkUpdate(b *testing.B) { + _, trie := NewTrie() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + trie.Update(fmt.Sprintf("aaaaaaaaaaaaaaa%d", j), "value") + } +} |