From 335f783cda6d22a7a6f32016c8fd9cf80e961bc5 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Wed, 2 Oct 2019 13:31:13 +0100 Subject: [PATCH] Profile work validation (#2322) * Profile work validation * Add CLI debug_proifile_validation to profile work validation * Replace previous verify command --- nano/nano_node/entry.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 9fb994f08..3b095fe38 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -117,8 +117,8 @@ int main (int argc, char * const * argv) ("debug_account_count", "Display the number of accounts") ("debug_mass_activity", "Generates fake debug activity") ("debug_profile_generate", "Profile work generation") + ("debug_profile_validate", "Profile work validation") ("debug_opencl", "OpenCL work generation") - ("debug_profile_verify", "Profile work verification") ("debug_profile_kdf", "Profile kdf function") ("debug_output_last_backtrace_dump", "Displays the contents of the latest backtrace in the event of a nano_node crash") ("debug_sys_logging", "Test the system logger") @@ -358,6 +358,24 @@ int main (int argc, char * const * argv) std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } + else if (vm.count ("debug_profile_validate")) + { + uint64_t difficulty{ nano::network_constants::publish_full_threshold }; + std::cerr << "Starting validation profile" << std::endl; + auto start (std::chrono::steady_clock::now ()); + bool valid{ false }; + nano::block_hash hash{ 0 }; + uint64_t count{ 10000000U }; // 10M + for (uint64_t i (0); i < count; ++i) + { + valid = nano::work_value (hash, i) > difficulty; + } + std::ostringstream oss (valid ? "true" : "false"); // IO forces compiler to not dismiss the variable + auto total_time (std::chrono::duration_cast (std::chrono::steady_clock::now () - start).count ()); + uint64_t average (total_time / count); + std::cout << "Average validation time: " << std::to_string (average) << " ns (" << std::to_string (static_cast (count * 1e9 / total_time)) << " validations/s)" << std::endl; + return average; + } else if (vm.count ("debug_opencl")) { nano::network_constants network_constants; @@ -468,25 +486,6 @@ int main (int argc, char * const * argv) result = -1; } } - else if (vm.count ("debug_profile_verify")) - { - nano::work_pool work (std::numeric_limits::max ()); - nano::change_block block (0, 0, nano::keypair ().prv, 0, 0); - std::cerr << "Starting verification profiling\n"; - while (true) - { - block.hashables.previous.qwords[0] += 1; - auto begin1 (std::chrono::high_resolution_clock::now ()); - for (uint64_t t (0); t < 1000000; ++t) - { - block.hashables.previous.qwords[0] += 1; - block.block_work_set (t); - nano::work_validate (block); - } - auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); - } - } else if (vm.count ("debug_output_last_backtrace_dump")) { if (boost::filesystem::exists ("nano_node_backtrace.dump"))