Electroneum
Loading...
Searching...
No Matches
performance_tests.h File Reference
#include <iostream>
#include <stdint.h>
#include <boost/chrono.hpp>
#include <boost/regex.hpp>
#include "misc_language.h"
#include "stats.h"
#include "common/perf_timer.h"
#include "common/timings.h"
Include dependency graph for performance_tests.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  performance_timer
struct  Params
class  test_runner< T >

Macros

#define QUOTEME(x)
#define TEST_PERFORMANCE0(filter, params, test_class)
#define TEST_PERFORMANCE1(filter, params, test_class, a0)
#define TEST_PERFORMANCE2(filter, params, test_class, a0, a1)
#define TEST_PERFORMANCE3(filter, params, test_class, a0, a1, a2)
#define TEST_PERFORMANCE4(filter, params, test_class, a0, a1, a2, a3)
#define TEST_PERFORMANCE5(filter, params, test_class, a0, a1, a2, a3, a4)
#define TEST_PERFORMANCE6(filter, params, test_class, a0, a1, a2, a3, a4, a5)

Functions

template<typename T>
void run_test (const std::string &filter, Params &params, const char *test_name)

Macro Definition Documentation

◆ QUOTEME

#define QUOTEME ( x)
Value:
#x

Definition at line 244 of file performance_tests.h.

◆ TEST_PERFORMANCE0

#define TEST_PERFORMANCE0 ( filter,
params,
test_class )
Value:
run_test< test_class >(filter, params, QUOTEME(test_class))
#define QUOTEME(x)
Definition chaingen.h:1055
void run_test(const std::string &filter, Params &params, const char *test_name)

Definition at line 245 of file performance_tests.h.

◆ TEST_PERFORMANCE1

#define TEST_PERFORMANCE1 ( filter,
params,
test_class,
a0 )
Value:
run_test< test_class<a0> >(filter, params, QUOTEME(test_class<a0>))

Definition at line 246 of file performance_tests.h.

◆ TEST_PERFORMANCE2

#define TEST_PERFORMANCE2 ( filter,
params,
test_class,
a0,
a1 )
Value:
run_test< test_class<a0, a1> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">")

Definition at line 247 of file performance_tests.h.

◆ TEST_PERFORMANCE3

#define TEST_PERFORMANCE3 ( filter,
params,
test_class,
a0,
a1,
a2 )
Value:
run_test< test_class<a0, a1, a2> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">")

Definition at line 248 of file performance_tests.h.

◆ TEST_PERFORMANCE4

#define TEST_PERFORMANCE4 ( filter,
params,
test_class,
a0,
a1,
a2,
a3 )
Value:
run_test< test_class<a0, a1, a2, a3> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ">")

Definition at line 249 of file performance_tests.h.

◆ TEST_PERFORMANCE5

#define TEST_PERFORMANCE5 ( filter,
params,
test_class,
a0,
a1,
a2,
a3,
a4 )
Value:
run_test< test_class<a0, a1, a2, a3, a4> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ">")

Definition at line 250 of file performance_tests.h.

◆ TEST_PERFORMANCE6

#define TEST_PERFORMANCE6 ( filter,
params,
test_class,
a0,
a1,
a2,
a3,
a4,
a5 )
Value:
run_test< test_class<a0, a1, a2, a3, a4, a5> >(filter, params, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ", " QUOTEME(a4) ", " QUOTEME(a5) ">")

Definition at line 251 of file performance_tests.h.

Function Documentation

◆ run_test()

template<typename T>
void run_test ( const std::string & filter,
Params & params,
const char * test_name )

Definition at line 166 of file performance_tests.h.

167{
168 boost::smatch match;
169 if (!filter.empty() && !boost::regex_match(std::string(test_name), match, boost::regex(filter)))
170 return;
171
172 test_runner<T> runner(params);
173 if (runner.run())
174 {
175 if (params.verbose)
176 {
177 std::cout << test_name << " - OK:\n";
178 std::cout << " loop count: " << T::loop_count * params.loop_multiplier << '\n';
179 std::cout << " elapsed: " << runner.elapsed_time() << " ms\n";
180 if (params.stats)
181 {
182 std::cout << " min: " << runner.get_min() << " ns\n";
183 std::cout << " max: " << runner.get_max() << " ns\n";
184 std::cout << " median: " << runner.get_median() << " ns\n";
185 std::cout << " std dev: " << runner.get_stddev() << " ns\n";
186 }
187 }
188 else
189 {
190 std::cout << test_name << " (" << T::loop_count * params.loop_multiplier << " calls) - OK:";
191 }
192 const char *unit = "ms";
193 double scale = 1000000;
194 uint64_t time_per_call = runner.time_per_call();
195 if (time_per_call < 100) {
196 scale = 1000;
197 time_per_call = runner.time_per_call(1000);
198#ifdef _WIN32
199 unit = "\xb5s";
200#else
201 unit = "µs";
202#endif
203 }
204 const auto quantiles = runner.get_quantiles(10);
205 double min = runner.get_min();
206 double max = runner.get_max();
207 double med = runner.get_median();
208 double mean = runner.get_mean();
209 double stddev = runner.get_stddev();
210 double npskew = runner.get_non_parametric_skew();
211
212 std::vector<TimingsDatabase::instance> prev_instances = params.td.get(test_name);
213 params.td.add(test_name, {time(NULL), runner.get_size(), min, max, mean, med, stddev, npskew, quantiles});
214
215 std::cout << (params.verbose ? " time per call: " : " ") << time_per_call << " " << unit << "/call" << (params.verbose ? "\n" : "");
216 if (params.stats)
217 {
218 uint64_t mins = min / scale;
219 uint64_t maxs = max / scale;
220 uint64_t meds = med / scale;
221 uint64_t p95s = quantiles[9] / scale;
222 uint64_t stddevs = stddev / scale;
223 std::string cmp;
224 if (!prev_instances.empty())
225 {
226 const TimingsDatabase::instance &prev_instance = prev_instances.back();
227 if (!runner.is_same_distribution(prev_instance.npoints, prev_instance.mean, prev_instance.stddev))
228 {
229 double pc = fabs(100. * (prev_instance.mean - runner.get_mean()) / prev_instance.mean);
230 cmp = ", " + std::to_string(pc) + "% " + (mean > prev_instance.mean ? "slower" : "faster");
231 }
232cmp += " -- " + std::to_string(prev_instance.mean);
233 }
234 std::cout << " (min " << mins << " " << unit << ", 90th " << p95s << " " << unit << ", median " << meds << " " << unit << ", std dev " << stddevs << " " << unit << ")" << cmp;
235 }
236 std::cout << std::endl;
237 }
238 else
239 {
240 std::cout << test_name << " - FAILED" << std::endl;
241 }
242}
time_t time
std::vector< instance > get(const char *name) const
void add(const char *name, const instance &data)
const base::type::char_t * unit
unsigned __int64 uint64_t
Definition stdint.h:136
unsigned loop_multiplier
TimingsDatabase td
Here is the call graph for this function: