From 962c72b624d3bd4fe46fde4ccb422c7978fce682 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 10 Feb 2017 18:44:47 +0000 Subject: [PATCH 1/3] performance_tests: initialize logging at startup --- tests/performance_tests/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index d08698433..1d3c79ca1 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -49,6 +49,9 @@ int main(int argc, char** argv) set_process_affinity(1); set_thread_high_priority(); + mlog_configure(mlog_get_default_log_path("performance_tests.log"), true); + mlog_set_log_level(0); + performance_timer timer; timer.start(); From cadada2d652102adebbfb1ced82da27a9a691b56 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 10 Feb 2017 18:45:18 +0000 Subject: [PATCH 2/3] performance_tests: add tests for sc_reduce32 and cn_fast_hash --- tests/performance_tests/cn_fast_hash.h | 57 ++++++++++++++++++++++++++ tests/performance_tests/main.cpp | 7 +++- tests/performance_tests/sc_reduce32.h | 53 ++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/performance_tests/cn_fast_hash.h create mode 100644 tests/performance_tests/sc_reduce32.h diff --git a/tests/performance_tests/cn_fast_hash.h b/tests/performance_tests/cn_fast_hash.h new file mode 100644 index 000000000..24f2bc5e2 --- /dev/null +++ b/tests/performance_tests/cn_fast_hash.h @@ -0,0 +1,57 @@ +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#pragma once + +#include "crypto/crypto.h" +#include "cryptonote_core/cryptonote_basic.h" + +template +class test_cn_fast_hash +{ +public: + static const size_t loop_count = bytes < 256 ? 100000 : bytes < 4096 ? 10000 : 1000; + + bool init() + { + crypto::rand(bytes, m_data.data()); + return true; + } + + bool test() + { + crypto::hash hash; + crypto::cn_fast_hash(&m_data, bytes, hash); + return true; + } + +private: + std::array m_data; +}; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 1d3c79ca1..cc9fe86ef 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2016, The Monero Project +// Copyright (c) 2014-2017, The Monero Project // // All rights reserved. // @@ -43,6 +43,8 @@ #include "generate_key_image_helper.h" #include "generate_keypair.h" #include "is_out_to_acc.h" +#include "sc_reduce32.h" +#include "cn_fast_hash.h" int main(int argc, char** argv) { @@ -105,8 +107,11 @@ int main(int argc, char** argv) TEST_PERFORMANCE0(test_derive_secret_key); TEST_PERFORMANCE0(test_ge_frombytes_vartime); TEST_PERFORMANCE0(test_generate_keypair); + TEST_PERFORMANCE0(test_sc_reduce32); TEST_PERFORMANCE0(test_cn_slow_hash); + TEST_PERFORMANCE1(test_cn_fast_hash, 32); + TEST_PERFORMANCE1(test_cn_fast_hash, 16384); std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl; diff --git a/tests/performance_tests/sc_reduce32.h b/tests/performance_tests/sc_reduce32.h new file mode 100644 index 000000000..bb3ad1694 --- /dev/null +++ b/tests/performance_tests/sc_reduce32.h @@ -0,0 +1,53 @@ +// Copyright (c) 2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#include "crypto/crypto.h" + +class test_sc_reduce32 +{ +public: + static const size_t loop_count = 10000000; + + bool init() + { + m_hash = crypto::rand(); + return true; + } + + bool test() + { + crypto::hash reduced = m_hash; + sc_reduce32((unsigned char*)reduced.data); + return true; + } + +private: + crypto::hash m_hash; +}; From 7403e56fb47164cd52d2db9107d82e0fffd9caf6 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 10 Feb 2017 19:43:06 +0000 Subject: [PATCH 3/3] performance_tests: report small time per call in microseconds This is to not report quick operations as 0 milliseconds --- tests/performance_tests/performance_tests.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h index 77707148b..88e8b592c 100644 --- a/tests/performance_tests/performance_tests.h +++ b/tests/performance_tests/performance_tests.h @@ -95,10 +95,10 @@ public: int elapsed_time() const { return m_elapsed; } - int time_per_call() const + int time_per_call(int scale = 1) const { static_assert(0 < T::loop_count, "T::loop_count must be greater than 0"); - return m_elapsed / T::loop_count; + return m_elapsed * scale / T::loop_count; } private: @@ -130,7 +130,17 @@ void run_test(const char* test_name) std::cout << test_name << " - OK:\n"; std::cout << " loop count: " << T::loop_count << '\n'; std::cout << " elapsed: " << runner.elapsed_time() << " ms\n"; - std::cout << " time per call: " << runner.time_per_call() << " ms/call\n" << std::endl; + const char *unit = "ms"; + int time_per_call = runner.time_per_call(); + if (time_per_call < 30000) { + time_per_call = runner.time_per_call(1000); +#ifdef _WIN32 + unit = "\xb5s"; +#else + unit = "µs"; +#endif + } + std::cout << " time per call: " << time_per_call << " " << unit << "/call\n" << std::endl; } else {