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
a5fcaa55
Unverified
Commit
a5fcaa55
authored
7 years ago
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie: make hasher benchmark meaningful post-caches
parent
0ed4d76c
master
v1.10.12
v1.10.12-modified
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
trie_test.go
trie/trie_test.go
+33
-11
No files found.
trie/trie_test.go
View file @
a5fcaa55
...
...
@@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"os"
"reflect"
...
...
@@ -30,7 +31,9 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
)
func
init
()
{
...
...
@@ -505,8 +508,6 @@ 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
...
...
@@ -549,18 +550,39 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
return
trie
}
func
benchHash
(
b
*
testing
.
B
,
e
binary
.
ByteOrder
)
{
// Benchmarks the trie hashing. Since the trie caches the result of any operation,
// we cannot use b.N as the number of hashing rouns, since all rounds apart from
// the first one will be NOOP. As such, we'll use b.N as the number of account to
// insert into the trie before measuring the hashing.
func
BenchmarkHash
(
b
*
testing
.
B
)
{
// Make the random benchmark deterministic
random
:=
rand
.
New
(
rand
.
NewSource
(
0
))
// Create a realistic account trie to hash
addresses
:=
make
([][
20
]
byte
,
b
.
N
)
for
i
:=
0
;
i
<
len
(
addresses
);
i
++
{
for
j
:=
0
;
j
<
len
(
addresses
[
i
]);
j
++
{
addresses
[
i
][
j
]
=
byte
(
random
.
Intn
(
256
))
}
}
accounts
:=
make
([][]
byte
,
len
(
addresses
))
for
i
:=
0
;
i
<
len
(
accounts
);
i
++
{
var
(
nonce
=
uint64
(
random
.
Int63
())
balance
=
new
(
big
.
Int
)
.
Rand
(
random
,
new
(
big
.
Int
)
.
Exp
(
common
.
Big2
,
common
.
Big256
,
nil
))
root
=
emptyRoot
code
=
crypto
.
Keccak256
(
nil
)
)
accounts
[
i
],
_
=
rlp
.
EncodeToBytes
([]
interface
{}{
nonce
,
balance
,
root
,
code
})
}
// Insert the accounts into the trie and hash it
trie
:=
newEmpty
()
k
:=
make
([]
byte
,
32
)
for
i
:=
0
;
i
<
benchElemCount
;
i
++
{
e
.
PutUint64
(
k
,
uint64
(
i
))
trie
.
Update
(
k
,
k
)
for
i
:=
0
;
i
<
len
(
addresses
);
i
++
{
trie
.
Update
(
crypto
.
Keccak256
(
addresses
[
i
][
:
]),
accounts
[
i
])
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
trie
.
Hash
()
}
b
.
ReportAllocs
()
trie
.
Hash
()
}
func
tempDB
()
(
string
,
Database
)
{
...
...
This diff is collapsed.
Click to expand it.
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