Electroneum
main.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2019, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #include <boost/regex.hpp>
32 
33 #include "common/util.h"
34 #include "common/command_line.h"
35 #include "performance_tests.h"
36 #include "performance_utils.h"
37 
38 // tests
39 #include "construct_tx.h"
40 #include "check_tx_signature.h"
41 #include "check_hash.h"
42 #include "cn_slow_hash.h"
43 #include "derive_public_key.h"
44 #include "derive_secret_key.h"
45 #include "ge_frombytes_vartime.h"
46 #include "ge_tobytes.h"
48 #include "generate_key_image.h"
50 #include "generate_keypair.h"
51 #include "signature.h"
52 #include "is_out_to_acc.h"
53 #include "subaddress_expand.h"
54 #include "sc_reduce32.h"
55 #include "sc_check.h"
56 #include "cn_fast_hash.h"
57 #include "rct_mlsag.h"
58 #include "equality.h"
59 #include "range_proof.h"
60 #include "rct_mlsag.h"
61 #include "bulletproof.h"
62 #include "crypto_ops.h"
63 #include "multiexp.h"
64 
65 namespace po = boost::program_options;
66 
67 int main(int argc, char** argv)
68 {
69  TRY_ENTRY();
73 
74  mlog_configure(mlog_get_default_log_path("performance_tests.log"), true);
75 
76  po::options_description desc_options("Command line options");
77  const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" };
78  const command_line::arg_descriptor<bool> arg_verbose = { "verbose", "Verbose output", false };
79  const command_line::arg_descriptor<bool> arg_stats = { "stats", "Including statistics (min/median)", false };
80  const command_line::arg_descriptor<unsigned> arg_loop_multiplier = { "loop-multiplier", "Run for that many times more loops", 1 };
81  const command_line::arg_descriptor<std::string> arg_timings_database = { "timings-database", "Keep timings history in a file" };
82  command_line::add_arg(desc_options, arg_filter);
83  command_line::add_arg(desc_options, arg_verbose);
84  command_line::add_arg(desc_options, arg_stats);
85  command_line::add_arg(desc_options, arg_loop_multiplier);
86  command_line::add_arg(desc_options, arg_timings_database);
87 
88  po::variables_map vm;
89  bool r = command_line::handle_error_helper(desc_options, [&]()
90  {
91  po::store(po::parse_command_line(argc, argv, desc_options), vm);
92  po::notify(vm);
93  return true;
94  });
95  if (!r)
96  return 1;
97 
98  const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
99  const std::string timings_database = command_line::get_arg(vm, arg_timings_database);
100  Params p;
101  if (!timings_database.empty())
102  p.td = TimingsDatabase(timings_database);
103  p.verbose = command_line::get_arg(vm, arg_verbose);
104  p.stats = command_line::get_arg(vm, arg_stats);
105  p.loop_multiplier = command_line::get_arg(vm, arg_loop_multiplier);
106 
107  performance_timer timer;
108  timer.start();
109 
110  TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 1, false);
111  TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 2, false);
112  TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 10, false);
113  TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 100, false);
114  TEST_PERFORMANCE3(filter, p, test_construct_tx, 1, 1000, false);
115 
116  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 1, false);
117  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 2, false);
118  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 10, false);
119  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 100, false);
120 
121  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 1, false);
122  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 2, false);
123  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 10, false);
124  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 100, false);
125 
126  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 1, false);
127  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 2, false);
128  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 10, false);
129  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 100, false);
130 
131  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 1, true);
132  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 2, true);
133  TEST_PERFORMANCE3(filter, p, test_construct_tx, 2, 10, true);
134 
135  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 1, true);
136  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 2, true);
137  TEST_PERFORMANCE3(filter, p, test_construct_tx, 10, 10, true);
138 
139  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 1, true);
140  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 2, true);
141  TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 10, true);
142 
146 
150 
154 
155  TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 1, 2, false);
156  TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 2, false);
157  TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 10, 2, false);
158  TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 100, 2, false);
159  TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 10, false);
160 
165 
174 
179 
184 
185  TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 1, 0, 1);
186  TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 0xffffffffffffffff, 0, 0xffffffffffffffff);
187  TEST_PERFORMANCE4(filter, p, test_check_hash, 0, 0xffffffffffffffff, 0, 1);
188  TEST_PERFORMANCE4(filter, p, test_check_hash, 1, 0, 1, 0);
189  TEST_PERFORMANCE4(filter, p, test_check_hash, 1, 0, 0, 1);
190  TEST_PERFORMANCE4(filter, p, test_check_hash, 0xffffffffffffffff, 0xffffffffffffffff, 0, 1);
191  TEST_PERFORMANCE4(filter, p, test_check_hash, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff);
192 
204  TEST_PERFORMANCE0(filter, p, test_sc_check);
205  TEST_PERFORMANCE1(filter, p, test_signature, false);
206  TEST_PERFORMANCE1(filter, p, test_signature, true);
207 
209 
210  TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 0);
211  TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 1);
212  TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 2);
213  TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 4);
214  TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 32);
215  TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 16384);
216 
217  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, false);
218  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, false);
219  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, false);
220  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, false);
221  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, true);
222  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, true);
223  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, true);
224  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, true);
225 
226  TEST_PERFORMANCE2(filter, p, test_equality, memcmp32, true);
227  TEST_PERFORMANCE2(filter, p, test_equality, memcmp32, false);
228  TEST_PERFORMANCE2(filter, p, test_equality, verify32, false);
229  TEST_PERFORMANCE2(filter, p, test_equality, verify32, false);
230 
231  TEST_PERFORMANCE1(filter, p, test_range_proof, true);
232  TEST_PERFORMANCE1(filter, p, test_range_proof, false);
233 
234  TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 1); // 1 bulletproof with 1 amount
235  TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 1);
236 
237  TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 2); // 1 bulletproof with 2 amounts
238  TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 2);
239 
240  TEST_PERFORMANCE2(filter, p, test_bulletproof, true, 15); // 1 bulletproof with 15 amounts
241  TEST_PERFORMANCE2(filter, p, test_bulletproof, false, 15);
242 
243  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 2, 1, 1, 0, 4);
244  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 2, 1, 1, 0, 4); // 4 proofs, each with 2 amounts
245  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 8, 1, 1, 0, 4);
246  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 8, 1, 1, 0, 4); // 4 proofs, each with 8 amounts
247  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 1, 1, 2, 0, 4);
248  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 1, 1, 2, 0, 4); // 4 proofs with 1, 2, 4, 8 amounts
249  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 1, 8, 1, 1, 4);
250  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 1, 8, 1, 1, 4); // 32 proofs, with 1, 2, 3, 4 amounts, 8 of each
251  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, false, 2, 1, 1, 0, 64);
252  TEST_PERFORMANCE6(filter, p, test_aggregated_bulletproof, true, 2, 1, 1, 0, 64); // 64 proof, each with 2 amounts
253 
254  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, false);
255  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, false);
256  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, false);
257  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, false);
258  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 3, true);
259  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 5, true);
260  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 10, true);
261  TEST_PERFORMANCE3(filter, p, test_ringct_mlsag, 1, 100, true);
262 
283 
296 
309 
322 
323 #if 1
333  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 7);
334  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 8);
335  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 9);
348 #else
457 
539  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 1);
540  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 2);
541  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 3);
542  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 4);
543  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 5);
544  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 6);
545  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 7);
546  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 8);
547  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 1024, 9);
548  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 1);
549  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 2);
550  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 3);
551  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 4);
552  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 5);
553  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 6);
554  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 7);
555  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 8);
556  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 2048, 9);
557  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 1);
558  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 2);
559  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 3);
560  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 4);
561  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 5);
562  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 6);
563  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 7);
564  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 8);
565  TEST_PERFORMANCE3(filter, p, test_multiexp, multiexp_pippenger, 4096, 9);
566 #endif
567 
568  std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;
569 
570  return 0;
571  CATCH_ENTRY_L0("main", 1);
572 }
int main(int argc, char *argv[])
Definition: main.cpp:63
::std::string string
Definition: gtest-port.h:1097
std::string mlog_get_default_log_path(const char *default_filename)
Definition: mlog.cpp:72
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition: mlog.cpp:148
std::string glob_to_regex(const std::string &val)
Definition: util.cpp:1012
#define TEST_PERFORMANCE4(filter, params, test_class, a0, a1, a2, a3)
#define TEST_PERFORMANCE5(filter, params, test_class, a0, a1, a2, a3, a4)
TimingsDatabase td
bool on_startup()
Definition: util.cpp:778
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
Definition: command_line.h:237
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
unsigned loop_multiplier
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
boost::program_options::basic_parsed_options< charT > parse_command_line(int argc, const charT *const argv[], const boost::program_options::options_description &desc, bool allow_unregistered=false)
Definition: command_line.h:224
#define TEST_PERFORMANCE6(filter, params, test_class, a0, a1, a2, a3, a4, a5)
void set_process_affinity(int core)
#define TEST_PERFORMANCE0(filter, params, test_class)
#define TEST_PERFORMANCE3(filter, params, test_class, a0, a1, a2)
void set_thread_high_priority()
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
#define TEST_PERFORMANCE1(filter, params, test_class, a0)
#define TEST_PERFORMANCE2(filter, params, test_class, a0, a1)