aboutsummaryrefslogtreecommitdiff
path: root/tests/performance_tests
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-12 23:23:17 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-12 23:23:17 +0200
commite6c29eb5fca83ca5748b8c61e004677623ab0ffb (patch)
tree2c41c8b82271da52f593667d194280012468f4b5 /tests/performance_tests
parentMerge pull request #1700 (diff)
parentperformance_tests: report small time per call in microseconds (diff)
downloadmonero-e6c29eb5fca83ca5748b8c61e004677623ab0ffb.tar.xz
Merge pull request #1706
7403e56f performance_tests: report small time per call in microseconds (moneromooo-monero) cadada2d performance_tests: add tests for sc_reduce32 and cn_fast_hash (moneromooo-monero) 962c72b6 performance_tests: initialize logging at startup (moneromooo-monero)
Diffstat (limited to 'tests/performance_tests')
-rw-r--r--tests/performance_tests/cn_fast_hash.h57
-rw-r--r--tests/performance_tests/main.cpp10
-rw-r--r--tests/performance_tests/performance_tests.h16
-rw-r--r--tests/performance_tests/sc_reduce32.h53
4 files changed, 132 insertions, 4 deletions
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<size_t bytes>
+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<uint8_t, bytes> m_data;
+};
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index d08698433..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,12 +43,17 @@
#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)
{
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();
@@ -102,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/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
{
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<crypto::hash>();
+ return true;
+ }
+
+ bool test()
+ {
+ crypto::hash reduced = m_hash;
+ sc_reduce32((unsigned char*)reduced.data);
+ return true;
+ }
+
+private:
+ crypto::hash m_hash;
+};