From 6fe8f1d6e6c18c5f4af687da6800320d0a966447 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 27 Sep 2018 17:24:21 +0200 Subject: [PATCH] Added parallel sign/verify test --- tests/thread/parallel_tests.cpp | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/thread/parallel_tests.cpp b/tests/thread/parallel_tests.cpp index b5b56f0..e1ad2b7 100644 --- a/tests/thread/parallel_tests.cpp +++ b/tests/thread/parallel_tests.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -122,4 +123,58 @@ BOOST_AUTO_TEST_CASE( hash_parallel ) hash_test().run(); } +BOOST_AUTO_TEST_CASE( sign_verify_parallel ) +{ + const fc::sha256 HASH = fc::sha256::hash(TEXT); + + std::vector keys; + keys.reserve(1000); + for( int i = 0; i < 1000; i++ ) + keys.push_back( fc::ecc::private_key::regenerate( fc::sha256::hash( TEXT + fc::to_string(i) ) ) ); + + std::vector sigs; + sigs.reserve( 10 * keys.size() ); + { + fc::time_point start = fc::time_point::now(); + for( int i = 0; i < 10; i++ ) + for( const auto& key: keys ) + sigs.push_back( key.sign_compact( HASH ) ); + fc::time_point end = fc::time_point::now(); + ilog( "${c} single-threaded signatures in ${t}µs", ("c",sigs.size())("t",end-start) ); + } + + { + fc::time_point start = fc::time_point::now(); + for( size_t i = 0; i < sigs.size(); i++ ) + BOOST_CHECK( keys[i % keys.size()].get_public_key() == fc::ecc::public_key( sigs[i], HASH ) ); + fc::time_point end = fc::time_point::now(); + ilog( "${c} single-threaded verifies in ${t}µs", ("c",sigs.size())("t",end-start) ); + } + + { + std::vector> results; + results.reserve( 10 * keys.size() ); + fc::time_point start = fc::time_point::now(); + for( int i = 0; i < 10; i++ ) + for( const auto& key: keys ) + results.push_back( fc::do_parallel( [&key,&HASH] () { return key.sign_compact( HASH ); } ) ); + for( auto& res : results ) + res.wait(); + fc::time_point end = fc::time_point::now(); + ilog( "${c} multi-threaded signatures in ${t}µs", ("c",sigs.size())("t",end-start) ); + } + + { + std::vector> results; + results.reserve( sigs.size() ); + fc::time_point start = fc::time_point::now(); + for( const auto& sig: sigs ) + results.push_back( fc::do_parallel( [&sig,&HASH] () { return fc::ecc::public_key( sig, HASH ); } ) ); + for( size_t i = 0; i < results.size(); i++ ) + BOOST_CHECK( keys[i % keys.size()].get_public_key() == results[i].wait() ); + fc::time_point end = fc::time_point::now(); + ilog( "${c} multi-threaded verifies in ${t}µs", ("c",sigs.size())("t",end-start) ); + } +} + BOOST_AUTO_TEST_SUITE_END()