Browse Source
Automated performance measurement Supersedes #843 because that one would have merged into the wrong branch. (Oh yeah and I rebased). **REBASED AND FORCE PUSHED**pull/145/head
zkbot
8 years ago
8 changed files with 342 additions and 1 deletions
@ -0,0 +1,103 @@ |
|||
#!/bin/bash |
|||
|
|||
set -e |
|||
|
|||
DATADIR=./benchmark-datadir |
|||
|
|||
function zcash_rpc { |
|||
./src/zcash-cli -rpcwait -rpcuser=user -rpcpassword=password -rpcport=5983 "$@" |
|||
} |
|||
|
|||
function zcashd_start { |
|||
rm -rf "$DATADIR" |
|||
mkdir -p "$DATADIR" |
|||
./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 & |
|||
ZCASHD_PID=$! |
|||
} |
|||
|
|||
function zcashd_stop { |
|||
zcash_rpc stop > /dev/null |
|||
wait $ZCASH_PID |
|||
} |
|||
|
|||
function zcashd_massif_start { |
|||
rm -rf "$DATADIR" |
|||
mkdir -p "$DATADIR" |
|||
rm -f massif.out |
|||
valgrind --tool=massif --time-unit=ms --massif-out-file=massif.out ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 & |
|||
ZCASHD_PID=$! |
|||
} |
|||
|
|||
function zcashd_massif_stop { |
|||
zcash_rpc stop > /dev/null |
|||
wait $ZCASHD_PID |
|||
ms_print massif.out |
|||
} |
|||
|
|||
RAWTXWITHPOUR=0200000001f7ed5a756eb4c303032ceff96ceeaf50aa1c0b35c1f25bbb0be65790cc6e918c0000000000ffffffff00000000000100f2052a01000000809698000000000000000000000000000000000000000000000000000000000000000000000000000000dae8308006ec0fbe6338e1d988a184e7ae4d5ebc286572751b92aa4817b2b1913b7e6010791444512992eab0a70e3ccc562d393990b031d90cacd94d1f6016596198e1bf67fe7770f77fc1ae1e4692d74b4e2ac219f1b5e5bfde4f3efe7db495e4508a0bcd1dd993c2f807c918d10cd7e3e4933c6ae2a12030033bc44f915b4aad044db18e2794ff5ab9b788f2f458d96fe120c4ef996f13a232223f33d4d5f64ea27fa770f229daa86cd12455d2d7f3d140c245beae06bc3cab6f94b74ea24c6bb63272b6077b05bed176f1d67d848a250d7203229a630811e9318efc4fde5823936e4ebf9a8f4941716de15b679270c4579f632fd907dcdef7bd343442612d51c08e75196364185757f4820bc0a2eb2124b95b3948f687100ff6b17461206fe2d349cf596b6f8b50ac6505904aad04b6da6514223ab17e94dba9a24baf89436f479b6819c3ea3b78f829ffa8401bb247b9a852e86c5f03033c3ce8b2b97c12c2a7b917d6b1adacbf0328dc66e02827f60dbe58cf32200b6ef90721688a393d40e2189e1ed9dcaa73718761097377b4c6e98c2e8bfe069110f414a0dde12fd6da2535568ef23fe085da8c6c57512180448d71fc21386f4312298cc07b3c16206a35211dc15b8630678d1c0ef91f81a321a1df57c0d816c480350c9d05e6f89eaf6ff7117bfa13192463ec949dd7b421eaa2fccbcb74fd35b8de4a4de679314f69c55573cbc21134146614c5e0c016b2d7e5fb1e260793360d7fd935fd83053020363932393634333932343530373938313439363431313035343330333737343835363938313036303035333438313438333034313230393236323938323333323333393636383936323438382035363636373135333432373537363739323131373135343636363532313236303838323634383737343334323635353738333335303632303436343936343430313031363937323237303235203020313230343935303533323333303434363736383730393531313337333638313139323333303536393738333335373031373831373730323239353335333034313637343039363633343334393920343031393536363932333236353639333331313730383539383837343834303733333532333835363636303530383235393634303332313539393038313335383830333135313635373135320a302031393138323031393635303431363635383138393733383032313033363136323937383836393334383532373538393630313836383936343934333735373439363139323231333330333538362031363738393839373130343930303438333032353531353935393339353935303030373438383934373139373530343432353238323834393432333036323033363433313034333639323832392036303237333833303831373630383738313630373636303739383036353232343433343839373638353539383836363831313232323731313838343736373935363439343837303735363935203139363834303931313134323037313434323332363837373733353337343237363832323335383832373937333631363039353233373332373234323230393937393739393936393135313330203020323037363234343236343137353631343431363530343830303037343436363238363932303830383131333636383638323637303437303038333632373136313131333237363336373936313320343832373532313838363631363030383630303739393033313830333330323235353734303036383636333331363830373239373838363131323735363436383332313237383037313130360a302031323639343439383431393536353235313538343330343637353938373531333737353839313939343733363439353237343833393036363232393233343837363032313231333435343831362031353836323533393532333935373432313835323031323136343636363334323938303133333031353335393638303033313332393834373734393437353532373130323636393034393536392030203937363433373334343639383336363633333033363238363939373136303138353931393230323934333237373633383935303231373332313832313735303739393030383136373336353120333630383738343430333133393638323832383732343932373937303836343932343633393637363037313739333038333536333130323635333732343837333536383430373137333939380a3020353032363138353739343930353038303537333436393133333034383939343734303338363535363634363430303835373733323637303538313233343633303237383532353939353730302031333737353638313035323637393032393430353831373435333136363233353132333737363836313733343734303039353431343032343337393234353133373830303834353638313233330a3020333539323435313835323432343437363230323036353638383031393437353939333339333634363736353736353137373135353631383836363639373239363538353131363832343739342031393938383834363235323230353838363735393932393630323630343233313235353630393931363431353039333636303739393333323238343436363736313039393839393630363739340a |
|||
|
|||
case "$1" in |
|||
time) |
|||
zcashd_start |
|||
case "$2" in |
|||
sleep) |
|||
zcash_rpc zcbenchmark sleep 10 |
|||
;; |
|||
parameterloading) |
|||
zcash_rpc zcbenchmark parameterloading 10 |
|||
;; |
|||
createjoinsplit) |
|||
zcash_rpc zcbenchmark createjoinsplit 10 |
|||
;; |
|||
verifyjoinsplit) |
|||
zcash_rpc zcbenchmark verifyjoinsplit 1000 "$RAWTXWITHPOUR" |
|||
;; |
|||
solveequihash) |
|||
zcash_rpc zcbenchmark solveequihash 10 |
|||
;; |
|||
verifyequihash) |
|||
zcash_rpc zcbenchmark verifyequihash 1000 |
|||
;; |
|||
*) |
|||
zcashd_stop |
|||
echo "Bad arguments." |
|||
exit 1 |
|||
esac |
|||
zcashd_stop |
|||
;; |
|||
memory) |
|||
zcashd_massif_start |
|||
case "$2" in |
|||
sleep) |
|||
zcash_rpc zcbenchmark sleep 1 |
|||
;; |
|||
parameterloading) |
|||
zcash_rpc zcbenchmark parameterloading 1 |
|||
;; |
|||
createjoinsplit) |
|||
zcash_rpc zcbenchmark createjoinsplit 1 |
|||
;; |
|||
verifyjoinsplit) |
|||
zcash_rpc zcbenchmark verifyjoinsplit 1 "$RAWTXWITHPOUR" |
|||
;; |
|||
solveequihash) |
|||
zcash_rpc zcbenchmark solveequihash 1 |
|||
;; |
|||
verifyequihash) |
|||
zcash_rpc zcbenchmark verifyequihash 1 |
|||
;; |
|||
*) |
|||
zcashd_massif_stop |
|||
echo "Bad arguments." |
|||
exit 1 |
|||
esac |
|||
zcashd_massif_stop |
|||
rm -f massif.out |
|||
;; |
|||
*) |
|||
echo "Bad arguments." |
|||
exit 1 |
|||
esac |
|||
|
|||
# Cleanup |
|||
rm -rf "$DATADIR" |
@ -0,0 +1,136 @@ |
|||
#include <unistd.h> |
|||
#include <boost/filesystem.hpp> |
|||
#include "zerocash/ZerocashParams.h" |
|||
#include "coins.h" |
|||
#include "util.h" |
|||
#include "init.h" |
|||
#include "primitives/transaction.h" |
|||
#include "crypto/equihash.h" |
|||
#include "chainparams.h" |
|||
#include "pow.h" |
|||
#include "sodium.h" |
|||
#include "streams.h" |
|||
|
|||
#include "zcbenchmarks.h" |
|||
|
|||
struct timeval tv_start; |
|||
|
|||
void timer_start() |
|||
{ |
|||
gettimeofday(&tv_start, 0); |
|||
} |
|||
|
|||
double timer_stop() |
|||
{ |
|||
double elapsed; |
|||
struct timeval tv_end; |
|||
gettimeofday(&tv_end, 0); |
|||
elapsed = double(tv_end.tv_sec-tv_start.tv_sec) + |
|||
(tv_end.tv_usec-tv_start.tv_usec)/double(1000000); |
|||
return elapsed; |
|||
} |
|||
|
|||
double benchmark_sleep() |
|||
{ |
|||
timer_start(); |
|||
sleep(1); |
|||
return timer_stop(); |
|||
} |
|||
|
|||
double benchmark_parameter_loading() |
|||
{ |
|||
// FIXME: this is duplicated with the actual loading code
|
|||
boost::filesystem::path pk_path = ZC_GetParamsDir() / "zc-testnet-public-alpha-proving.key"; |
|||
boost::filesystem::path vk_path = ZC_GetParamsDir() / "zc-testnet-public-alpha-verification.key"; |
|||
|
|||
timer_start(); |
|||
auto vk_loaded = libzerocash::ZerocashParams::LoadVerificationKeyFromFile( |
|||
vk_path.string(), |
|||
INCREMENTAL_MERKLE_TREE_DEPTH |
|||
); |
|||
auto pk_loaded = libzerocash::ZerocashParams::LoadProvingKeyFromFile( |
|||
pk_path.string(), |
|||
INCREMENTAL_MERKLE_TREE_DEPTH |
|||
); |
|||
libzerocash::ZerocashParams zerocashParams = libzerocash::ZerocashParams( |
|||
INCREMENTAL_MERKLE_TREE_DEPTH, |
|||
&pk_loaded, |
|||
&vk_loaded |
|||
); |
|||
return timer_stop(); |
|||
} |
|||
|
|||
double benchmark_create_joinsplit() |
|||
{ |
|||
CScript scriptPubKey; |
|||
|
|||
std::vector<PourInput> vpourin; |
|||
std::vector<PourOutput> vpourout; |
|||
|
|||
while (vpourin.size() < NUM_POUR_INPUTS) { |
|||
vpourin.push_back(PourInput(INCREMENTAL_MERKLE_TREE_DEPTH)); |
|||
} |
|||
|
|||
while (vpourout.size() < NUM_POUR_OUTPUTS) { |
|||
vpourout.push_back(PourOutput(0)); |
|||
} |
|||
|
|||
/* Get the anchor of an empty commitment tree. */ |
|||
IncrementalMerkleTree blank_tree(INCREMENTAL_MERKLE_TREE_DEPTH); |
|||
std::vector<unsigned char> newrt_v(32); |
|||
blank_tree.getRootValue(newrt_v); |
|||
uint256 anchor = uint256(newrt_v); |
|||
|
|||
timer_start(); |
|||
CPourTx pourtx(*pzerocashParams, |
|||
scriptPubKey, |
|||
anchor, |
|||
{vpourin[0], vpourin[1]}, |
|||
{vpourout[0], vpourout[1]}, |
|||
0, |
|||
0); |
|||
double ret = timer_stop(); |
|||
assert(pourtx.Verify(*pzerocashParams)); |
|||
return ret; |
|||
} |
|||
|
|||
double benchmark_verify_joinsplit(const CPourTx &joinsplit) |
|||
{ |
|||
timer_start(); |
|||
joinsplit.Verify(*pzerocashParams); |
|||
return timer_stop(); |
|||
} |
|||
|
|||
double benchmark_solve_equihash() |
|||
{ |
|||
CBlock pblock; |
|||
CEquihashInput I{pblock}; |
|||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); |
|||
ss << I; |
|||
|
|||
Equihash eh {Params(CBaseChainParams::MAIN).EquihashN(), Params(CBaseChainParams::MAIN).EquihashK()}; |
|||
crypto_generichash_blake2b_state eh_state; |
|||
eh.InitialiseState(eh_state); |
|||
crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size()); |
|||
|
|||
uint256 nonce; |
|||
randombytes_buf(nonce.begin(), 32); |
|||
crypto_generichash_blake2b_update(&eh_state, |
|||
nonce.begin(), |
|||
nonce.size()); |
|||
|
|||
timer_start(); |
|||
eh.BasicSolve(eh_state); |
|||
return timer_stop(); |
|||
} |
|||
|
|||
double benchmark_verify_equihash() |
|||
{ |
|||
CChainParams params = Params(CBaseChainParams::MAIN); |
|||
CBlock genesis = Params(CBaseChainParams::MAIN).GenesisBlock(); |
|||
CBlockHeader genesis_header = genesis.GetBlockHeader(); |
|||
timer_start(); |
|||
CheckEquihashSolution(&genesis_header, params); |
|||
return timer_stop(); |
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
#ifndef BENCHMARKS_H |
|||
#define BENCHMARKS_H |
|||
|
|||
#include <sys/time.h> |
|||
#include <stdlib.h> |
|||
|
|||
extern double benchmark_sleep(); |
|||
extern double benchmark_parameter_loading(); |
|||
extern double benchmark_create_joinsplit(); |
|||
extern double benchmark_solve_equihash(); |
|||
extern double benchmark_verify_joinsplit(const CPourTx &joinsplit); |
|||
extern double benchmark_verify_equihash(); |
|||
|
|||
#endif |
Loading…
Reference in new issue