Measure multithreaded solveequihash time per-thread
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "coins.h"
|
||||
#include "util.h"
|
||||
#include "init.h"
|
||||
@@ -24,14 +26,12 @@
|
||||
|
||||
using namespace libzcash;
|
||||
|
||||
struct timeval tv_start;
|
||||
|
||||
void timer_start()
|
||||
void timer_start(timeval &tv_start)
|
||||
{
|
||||
gettimeofday(&tv_start, 0);
|
||||
}
|
||||
|
||||
double timer_stop()
|
||||
double timer_stop(timeval &tv_start)
|
||||
{
|
||||
double elapsed;
|
||||
struct timeval tv_end;
|
||||
@@ -43,9 +43,10 @@ double timer_stop()
|
||||
|
||||
double benchmark_sleep()
|
||||
{
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
sleep(1);
|
||||
return timer_stop();
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_parameter_loading()
|
||||
@@ -54,7 +55,8 @@ double benchmark_parameter_loading()
|
||||
boost::filesystem::path pk_path = ZC_GetParamsDir() / "z9-proving.key";
|
||||
boost::filesystem::path vk_path = ZC_GetParamsDir() / "z9-verifying.key";
|
||||
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
|
||||
auto newParams = ZCJoinSplit::Unopened();
|
||||
|
||||
@@ -62,7 +64,7 @@ double benchmark_parameter_loading()
|
||||
newParams->setProvingKeyPath(pk_path.string());
|
||||
newParams->loadProvingKey();
|
||||
|
||||
double ret = timer_stop();
|
||||
double ret = timer_stop(tv_start);
|
||||
|
||||
delete newParams;
|
||||
|
||||
@@ -76,7 +78,8 @@ double benchmark_create_joinsplit()
|
||||
/* Get the anchor of an empty commitment tree. */
|
||||
uint256 anchor = ZCIncrementalMerkleTree().root();
|
||||
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
JSDescription jsdesc(*pzcashParams,
|
||||
pubKeyHash,
|
||||
anchor,
|
||||
@@ -84,7 +87,7 @@ double benchmark_create_joinsplit()
|
||||
{JSOutput(), JSOutput()},
|
||||
0,
|
||||
0);
|
||||
double ret = timer_stop();
|
||||
double ret = timer_stop(tv_start);
|
||||
|
||||
assert(jsdesc.Verify(*pzcashParams, pubKeyHash));
|
||||
return ret;
|
||||
@@ -92,13 +95,14 @@ double benchmark_create_joinsplit()
|
||||
|
||||
double benchmark_verify_joinsplit(const JSDescription &joinsplit)
|
||||
{
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
uint256 pubKeyHash;
|
||||
joinsplit.Verify(*pzcashParams, pubKeyHash);
|
||||
return timer_stop();
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_solve_equihash(bool time)
|
||||
double benchmark_solve_equihash()
|
||||
{
|
||||
CBlock pblock;
|
||||
CEquihashInput I{pblock};
|
||||
@@ -117,25 +121,33 @@ double benchmark_solve_equihash(bool time)
|
||||
nonce.begin(),
|
||||
nonce.size());
|
||||
|
||||
if (time)
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
std::set<std::vector<unsigned int>> solns;
|
||||
EhOptimisedSolveUncancellable(n, k, eh_state,
|
||||
[](std::vector<unsigned char> soln) { return false; });
|
||||
if (time)
|
||||
return timer_stop();
|
||||
else
|
||||
return 0;
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_solve_equihash_threaded(int nThreads)
|
||||
std::vector<double> benchmark_solve_equihash_threaded(int nThreads)
|
||||
{
|
||||
boost::thread_group solverThreads;
|
||||
timer_start();
|
||||
for (int i = 0; i < nThreads; i++)
|
||||
solverThreads.create_thread(boost::bind(&benchmark_solve_equihash, false));
|
||||
solverThreads.join_all();
|
||||
return timer_stop();
|
||||
std::vector<double> ret;
|
||||
std::vector<std::future<double>> tasks;
|
||||
std::vector<std::thread> threads;
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
std::packaged_task<double(void)> task(&benchmark_solve_equihash);
|
||||
tasks.emplace_back(task.get_future());
|
||||
threads.emplace_back(std::move(task));
|
||||
}
|
||||
std::future_status status;
|
||||
for (auto it = tasks.begin(); it != tasks.end(); it++) {
|
||||
it->wait();
|
||||
ret.push_back(it->get());
|
||||
}
|
||||
for (auto it = threads.begin(); it != threads.end(); it++) {
|
||||
it->join();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double benchmark_verify_equihash()
|
||||
@@ -143,9 +155,10 @@ double benchmark_verify_equihash()
|
||||
CChainParams params = Params(CBaseChainParams::MAIN);
|
||||
CBlock genesis = Params(CBaseChainParams::MAIN).GenesisBlock();
|
||||
CBlockHeader genesis_header = genesis.GetBlockHeader();
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
CheckEquihashSolution(&genesis_header, params);
|
||||
return timer_stop();
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
double benchmark_large_tx()
|
||||
@@ -197,7 +210,8 @@ double benchmark_large_tx()
|
||||
CTransaction final_spending_tx(spending_tx);
|
||||
|
||||
// Benchmark signature verification costs:
|
||||
timer_start();
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
for (size_t i = 0; i < NUM_INPUTS; i++) {
|
||||
ScriptError serror = SCRIPT_ERR_OK;
|
||||
assert(VerifyScript(final_spending_tx.vin[i].scriptSig,
|
||||
@@ -206,6 +220,6 @@ double benchmark_large_tx()
|
||||
TransactionSignatureChecker(&final_spending_tx, i),
|
||||
&serror));
|
||||
}
|
||||
return timer_stop();
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user