Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
a5fcaa55
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a5fcaa55
编写于
10月 13, 2017
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
trie: make hasher benchmark meaningful post-caches
上级
0ed4d76c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
11 deletion
+33
-11
trie/trie_test.go
trie/trie_test.go
+33
-11
未找到文件。
trie/trie_test.go
浏览文件 @
a5fcaa55
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"math/big"
"math/rand"
"math/rand"
"os"
"os"
"reflect"
"reflect"
...
@@ -30,7 +31,9 @@ import (
...
@@ -30,7 +31,9 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
)
)
func
init
()
{
func
init
()
{
...
@@ -505,8 +508,6 @@ func BenchmarkGet(b *testing.B) { benchGet(b, false) }
...
@@ -505,8 +508,6 @@ func BenchmarkGet(b *testing.B) { benchGet(b, false) }
func
BenchmarkGetDB
(
b
*
testing
.
B
)
{
benchGet
(
b
,
true
)
}
func
BenchmarkGetDB
(
b
*
testing
.
B
)
{
benchGet
(
b
,
true
)
}
func
BenchmarkUpdateBE
(
b
*
testing
.
B
)
{
benchUpdate
(
b
,
binary
.
BigEndian
)
}
func
BenchmarkUpdateBE
(
b
*
testing
.
B
)
{
benchUpdate
(
b
,
binary
.
BigEndian
)
}
func
BenchmarkUpdateLE
(
b
*
testing
.
B
)
{
benchUpdate
(
b
,
binary
.
LittleEndian
)
}
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
const
benchElemCount
=
20000
...
@@ -549,18 +550,39 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
...
@@ -549,18 +550,39 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
return
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
()
trie
:=
newEmpty
()
k
:=
make
([]
byte
,
32
)
for
i
:=
0
;
i
<
len
(
addresses
);
i
++
{
for
i
:=
0
;
i
<
benchElemCount
;
i
++
{
trie
.
Update
(
crypto
.
Keccak256
(
addresses
[
i
][
:
]),
accounts
[
i
])
e
.
PutUint64
(
k
,
uint64
(
i
))
trie
.
Update
(
k
,
k
)
}
}
b
.
ResetTimer
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
b
.
ReportAllocs
()
trie
.
Hash
()
trie
.
Hash
()
}
}
}
func
tempDB
()
(
string
,
Database
)
{
func
tempDB
()
(
string
,
Database
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录