forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2018 The Dash Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "bench.h" | ||
|
||
#include "key.h" | ||
|
||
static void ECDSASign(benchmark::State& state) | ||
{ | ||
std::vector<CKey> keys; | ||
std::vector<uint256> hashes; | ||
for (size_t i = 0; i < 100; i++) { | ||
CKey k; | ||
k.MakeNewKey(false); | ||
keys.emplace_back(k); | ||
hashes.emplace_back(::SerializeHash((int)i)); | ||
} | ||
|
||
// Benchmark. | ||
size_t i = 0; | ||
while (state.KeepRunning()) { | ||
std::vector<unsigned char> sig; | ||
keys[i].Sign(hashes[i], sig); | ||
i = (i + 1) % keys.size(); | ||
} | ||
} | ||
|
||
static void ECDSAVerify(benchmark::State& state) | ||
{ | ||
std::vector<CPubKey> keys; | ||
std::vector<uint256> hashes; | ||
std::vector<std::vector<unsigned char>> sigs; | ||
for (size_t i = 0; i < 100; i++) { | ||
CKey k; | ||
k.MakeNewKey(false); | ||
keys.emplace_back(k.GetPubKey()); | ||
hashes.emplace_back(::SerializeHash((int)i)); | ||
std::vector<unsigned char> sig; | ||
k.Sign(hashes[i], sig); | ||
sigs.emplace_back(sig); | ||
} | ||
|
||
// Benchmark. | ||
size_t i = 0; | ||
while (state.KeepRunning()) { | ||
keys[i].Verify(hashes[i], sigs[i]); | ||
i = (i + 1) % keys.size(); | ||
} | ||
} | ||
|
||
static void ECDSAVerify_LargeBlock(benchmark::State& state) | ||
{ | ||
std::vector<CPubKey> keys; | ||
std::vector<uint256> hashes; | ||
std::vector<std::vector<unsigned char>> sigs; | ||
for (size_t i = 0; i < 1000; i++) { | ||
CKey k; | ||
k.MakeNewKey(false); | ||
keys.emplace_back(k.GetPubKey()); | ||
hashes.emplace_back(::SerializeHash((int)i)); | ||
std::vector<unsigned char> sig; | ||
k.Sign(hashes[i], sig); | ||
sigs.emplace_back(sig); | ||
} | ||
|
||
// Benchmark. | ||
while (state.KeepRunning()) { | ||
for (size_t i = 0; i < keys.size(); i++) { | ||
keys[i].Verify(hashes[i], sigs[i]); | ||
} | ||
} | ||
} | ||
|
||
BENCHMARK(ECDSASign) | ||
BENCHMARK(ECDSAVerify) | ||
BENCHMARK(ECDSAVerify_LargeBlock) |