Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
8c31d289
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
8c31d289
编写于
4月 07, 2018
作者:
M
Martin Holst Swende
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: add blockchain benchmarks
上级
14c9215d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
111 addition
and
0 deletion
+111
-0
core/blockchain_test.go
core/blockchain_test.go
+111
-0
未找到文件。
core/blockchain_test.go
浏览文件 @
8c31d289
...
...
@@ -1338,3 +1338,114 @@ func TestLargeReorgTrieGC(t *testing.T) {
}
}
}
// Benchmarks large blocks with value transfers to non-existing accounts
func
benchmarkLargeNumberOfValueToNonexisting
(
b
*
testing
.
B
,
numTxs
,
numBlocks
int
,
recipientFn
func
(
uint64
)
common
.
Address
,
dataFn
func
(
uint64
)
[]
byte
)
{
var
(
signer
=
types
.
HomesteadSigner
{}
testBankKey
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
testBankAddress
=
crypto
.
PubkeyToAddress
(
testBankKey
.
PublicKey
)
bankFunds
=
big
.
NewInt
(
100000000000000000
)
gspec
=
Genesis
{
Config
:
params
.
TestChainConfig
,
Alloc
:
GenesisAlloc
{
testBankAddress
:
{
Balance
:
bankFunds
},
common
.
HexToAddress
(
"0xc0de"
)
:
{
Code
:
[]
byte
{
0x60
,
0x01
,
0x50
},
Balance
:
big
.
NewInt
(
0
),
},
// push 1, pop
},
GasLimit
:
100e6
,
// 100 M
}
)
// Generate the original common chain segment and the two competing forks
engine
:=
ethash
.
NewFaker
()
db
,
_
:=
ethdb
.
NewMemDatabase
()
genesis
:=
gspec
.
MustCommit
(
db
)
blockGenerator
:=
func
(
i
int
,
block
*
BlockGen
)
{
block
.
SetCoinbase
(
common
.
Address
{
1
})
for
txi
:=
0
;
txi
<
numTxs
;
txi
++
{
uniq
:=
uint64
(
i
*
numTxs
+
txi
)
recipient
:=
recipientFn
(
uniq
)
//recipient := common.BigToAddress(big.NewInt(0).SetUint64(1337 + uniq))
tx
,
err
:=
types
.
SignTx
(
types
.
NewTransaction
(
uniq
,
recipient
,
big
.
NewInt
(
1
),
params
.
TxGas
,
big
.
NewInt
(
1
),
nil
),
signer
,
testBankKey
)
if
err
!=
nil
{
b
.
Error
(
err
)
}
block
.
AddTx
(
tx
)
}
}
shared
,
_
:=
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
engine
,
db
,
numBlocks
,
blockGenerator
)
b
.
StopTimer
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// Import the shared chain and the original canonical one
diskdb
,
_
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
if
err
!=
nil
{
b
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
b
.
StartTimer
()
if
_
,
err
:=
chain
.
InsertChain
(
shared
);
err
!=
nil
{
b
.
Fatalf
(
"failed to insert shared chain: %v"
,
err
)
}
b
.
StopTimer
()
if
got
:=
chain
.
CurrentBlock
()
.
Transactions
()
.
Len
();
got
!=
numTxs
*
numBlocks
{
b
.
Fatalf
(
"Transactions were not included, expected %d, got %d"
,
(
numTxs
*
numBlocks
),
got
)
}
}
}
func
BenchmarkBlockChain_1x1000ValueTransferToNonexisting
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
1337
+
nonce
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
func
BenchmarkBlockChain_1x1000ValueTransferToExisting
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
b
.
StopTimer
()
b
.
ResetTimer
()
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
1337
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
func
BenchmarkBlockChain_1x1000Executions
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
b
.
StopTimer
()
b
.
ResetTimer
()
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
0xc0de
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录