mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-12-23 05:37:46 +00:00
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)
This commit is contained in:
commit
e6c29eb5fc
4 changed files with 132 additions and 4 deletions
57
tests/performance_tests/cn_fast_hash.h
Normal file
57
tests/performance_tests/cn_fast_hash.h
Normal file
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
53
tests/performance_tests/sc_reduce32.h
Normal file
53
tests/performance_tests/sc_reduce32.h
Normal file
|
@ -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;
|
||||
};
|
Loading…
Reference in a new issue