Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6b91a4ab
Commit
6b91a4ab
authored
Jun 30, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: improve benchmarks
parent
e56cbc22
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
34 deletions
+72
-34
trie_test.go
trie/trie_test.go
+72
-34
No files found.
trie/trie_test.go
View file @
6b91a4ab
...
@@ -18,11 +18,15 @@ package trie
...
@@ -18,11 +18,15 @@ package trie
import
(
import
(
"bytes"
"bytes"
"encoding/binary"
"fmt"
"fmt"
"io/ioutil"
"os"
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
)
)
type
Db
map
[
string
][]
byte
type
Db
map
[
string
][]
byte
...
@@ -100,7 +104,6 @@ func TestGet(t *testing.T) {
...
@@ -100,7 +104,6 @@ func TestGet(t *testing.T) {
func
TestDelete
(
t
*
testing
.
T
)
{
func
TestDelete
(
t
*
testing
.
T
)
{
trie
:=
NewEmpty
()
trie
:=
NewEmpty
()
vals
:=
[]
struct
{
k
,
v
string
}{
vals
:=
[]
struct
{
k
,
v
string
}{
{
"do"
,
"verb"
},
{
"do"
,
"verb"
},
{
"ether"
,
"wookiedoo"
},
{
"ether"
,
"wookiedoo"
},
...
@@ -254,39 +257,6 @@ func TestOutput(t *testing.T) {
...
@@ -254,39 +257,6 @@ func TestOutput(t *testing.T) {
fmt
.
Println
(
trie2
.
root
)
fmt
.
Println
(
trie2
.
root
)
}
}
func
BenchmarkGets
(
b
*
testing
.
B
)
{
trie
:=
NewEmpty
()
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
.
UpdateString
(
val
.
k
,
val
.
v
)
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
trie
.
Get
([]
byte
(
"horse"
))
}
}
func
BenchmarkUpdate
(
b
*
testing
.
B
)
{
trie
:=
NewEmpty
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
trie
.
UpdateString
(
fmt
.
Sprintf
(
"aaaaaaaaa%d"
,
i
),
"value"
)
}
trie
.
Hash
()
}
type
kv
struct
{
type
kv
struct
{
k
,
v
[]
byte
k
,
v
[]
byte
t
bool
t
bool
...
@@ -352,3 +322,71 @@ func TestSecureDelete(t *testing.T) {
...
@@ -352,3 +322,71 @@ func TestSecureDelete(t *testing.T) {
t
.
Errorf
(
"expected %x got %x"
,
exp
,
hash
)
t
.
Errorf
(
"expected %x got %x"
,
exp
,
hash
)
}
}
}
}
func
BenchmarkGet
(
b
*
testing
.
B
)
{
benchGet
(
b
,
false
)
}
func
BenchmarkGetDB
(
b
*
testing
.
B
)
{
benchGet
(
b
,
true
)
}
func
BenchmarkUpdateBE
(
b
*
testing
.
B
)
{
benchUpdate
(
b
,
binary
.
BigEndian
)
}
func
BenchmarkUpdateLE
(
b
*
testing
.
B
)
{
benchUpdate
(
b
,
binary
.
LittleEndian
)
}
func
BenchmarkHashBE
(
b
*
testing
.
B
)
{
benchHash
(
b
,
binary
.
BigEndian
)
}
func
BenchmarkHashLE
(
b
*
testing
.
B
)
{
benchHash
(
b
,
binary
.
LittleEndian
)
}
const
benchElemCount
=
20000
func
benchGet
(
b
*
testing
.
B
,
commit
bool
)
{
trie
:=
New
(
nil
,
nil
)
if
commit
{
dir
,
tmpdb
:=
tempDB
()
defer
os
.
RemoveAll
(
dir
)
trie
=
New
(
nil
,
tmpdb
)
}
k
:=
make
([]
byte
,
32
)
for
i
:=
0
;
i
<
benchElemCount
;
i
++
{
binary
.
LittleEndian
.
PutUint64
(
k
,
uint64
(
i
))
trie
.
Update
(
k
,
k
)
}
binary
.
LittleEndian
.
PutUint64
(
k
,
benchElemCount
/
2
)
if
commit
{
trie
.
Commit
()
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
trie
.
Get
(
k
)
}
}
func
benchUpdate
(
b
*
testing
.
B
,
e
binary
.
ByteOrder
)
*
Trie
{
trie
:=
NewEmpty
()
k
:=
make
([]
byte
,
32
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
e
.
PutUint64
(
k
,
uint64
(
i
))
trie
.
Update
(
k
,
k
)
}
return
trie
}
func
benchHash
(
b
*
testing
.
B
,
e
binary
.
ByteOrder
)
{
trie
:=
NewEmpty
()
k
:=
make
([]
byte
,
32
)
for
i
:=
0
;
i
<
benchElemCount
;
i
++
{
e
.
PutUint64
(
k
,
uint64
(
i
))
trie
.
Update
(
k
,
k
)
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
trie
.
Hash
()
}
}
func
tempDB
()
(
string
,
Backend
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"trie-bench"
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"can't create temporary directory: %v"
,
err
))
}
db
,
err
:=
ethdb
.
NewLDBDatabase
(
dir
,
300
*
1024
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"can't create temporary database: %v"
,
err
))
}
return
dir
,
db
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment