mesure performance

This commit is contained in:
crypro.zoidberg 2019-02-20 20:02:43 +01:00
parent 9d0f8c9966
commit 5200387d23
4 changed files with 39 additions and 3 deletions

View file

@ -129,5 +129,25 @@ namespace crypto
}
return true;
}
#define WK2_COUNT 9
bool generate_scratchpad2(const crypto::hash& seed_data, std::vector<crypto::hash>& result_data, uint64_t target_size)
{
//this is very basic implementation, not considered for production (possible to reduce memory by keeping only every x10 item and calc it instead of read)
//TODO: research safe way for scratchpad generation
result_data.resize(target_size);
result_data[0] = crypto::cn_fast_hash(&seed_data, sizeof(seed_data));
//crypto::hash = get_transaction_hash()
for (size_t i = 1; i < target_size; i++)
{
result_data[i] = crypto::cn_fast_hash(&result_data[i - 1], sizeof(result_data[i - 1]));
for (size_t j = 0; j != WK2_COUNT; j++)
{
result_data[i] = crypto::cn_fast_hash(&result_data[i], sizeof(result_data[i]));
}
}
return true;
}
}

View file

@ -281,7 +281,7 @@ namespace crypto
}
//------------------------------------------------------------------
bool generate_scratchpad(const crypto::hash& source_data, std::vector<crypto::hash>& result_data, uint64_t target_size);
bool generate_scratchpad2(const crypto::hash& source_data, std::vector<crypto::hash>& result_data, uint64_t target_size);
}

View file

@ -7,7 +7,7 @@
#include "crypto/crypto.h"
#include "currency_core/currency_basic.h"
#include "profile_tools.h"
extern "C" {
#include "crypto/keccak.h"
@ -154,6 +154,21 @@ protected:
#define max_measere_scratchpad 10000000
#endif
#define measere_rounds 10000
void generate_scratchpad()
{
crypto::hash seed = crypto::cn_fast_hash("sdssdsffdss", 10);
std::vector<crypto::hash> scratchpad;
size_t count = 500000000 / 32;
TIME_MEASURE_START_MS(gen_time);
LOG_PRINT_L0("Generating....");
crypto::generate_scratchpad2(seed, scratchpad, count);
TIME_MEASURE_FINISH_MS(gen_time);
LOG_PRINT_L0("Generated scratchpad " << (scratchpad.size() * 32) / (1024 * 1024) << "MB in " << gen_time << "ms");
}
void measure_keccak_over_scratchpad()
{
std::cout << std::setw(20) << std::left << "sz\t" <<

View file

@ -35,7 +35,8 @@ int main(int argc, char** argv)
performance_timer timer;
timer.start();
measure_keccak_over_scratchpad();
generate_scratchpad();
//measure_keccak_over_scratchpad();
/*
TEST_PERFORMANCE2(test_construct_tx, 1, 1);