25 #ifndef Common_TestUtils_h
26 #define Common_TestUtils_h
33 #include <boost/bind.hpp>
39 #define HT_BENCH_OUT(_label_, _n_, _w_) do { \
40 std::cout << ThisThread::get_id() <<": "<< (_label_) <<": " \
41 << (_n_) / _w_.elapsed() <<"/s ("<< _w_.elapsed() / (_n_) * 1e6 \
42 <<"ns per)"<< std::endl; \
45 #define HT_BENCH(_label_, _code_, _n_) do { \
47 for (int i = 0, _n = (_n_); i < _n; ++i) { _code_; } \
49 HT_BENCH_OUT(_label_, _n_, _w); \
52 #define HT_BENCH1(_label_, _code_, _n_) do { \
53 Stopwatch _w; _code_; _w.stop(); \
54 HT_BENCH_OUT(_label_, _n_, _w); \
93 std::lock_guard<std::mutex> lock(
m_mutex);
111 return out <<
"min=" << stat.
min() <<
" max=" << stat.
max()
112 <<
" mean=" << stat.
mean() <<
" stdev=" << stat.
stdev();
119 template <
typename FunT>
129 std::cout << ThisThread::get_id() <<
": ";
133 std::cout <<
"Elapsed: " << w.
elapsed() <<
"s\n ";
139 std::cout << std::endl;
151 template <
typename FunT>
152 void serial_run(FunT fun,
size_t n,
bool proc_stat =
false) {
159 std::cout <<
"Elapsed times: " << stat <<
"s\n" << std::endl;
166 template <
typename FunT>
175 std::cout <<
"Elapsed times: " << stat <<
"s\n" << std::endl;
184 template <
typename FunT>
191 size_t threads = props->get_i32(
"threads", 0);
196 serial_run(fun, props->get_i32(
"repeats", 3), proc_stat);
207 (
"repeats,r",
i32()->default_value(3),
"Number of repeats")
208 (
"threads,t",
i32(),
"Number of threads")
209 (
"num-items,n",
i32()->default_value(100000),
"Number of items")
212 (
"components",
strs(),
"test components")
Interface and base of config policy.
double elapsed()
Returns the elapsed time.
Cons< TestPolicy, DefaultPolicy > DefaultTestPolicy
PropertiesPtr properties
This singleton map stores all options.
The Stopwatch measures elapsed time.
void run_test(FunT fun, bool proc_stat=false, const Properties *props=0)
Runs a test based on command line parameters:
TestFun(FunT fun, bool proc_stat=false, TestStat *stat=NULL)
static const ProcStat & proc_stat()
Retrieves updated Process statistics (see SystemInfo.h)
void parallel_run(FunT fun, size_t n, bool proc_stat=false)
Runs a test in parallel n times in a row while accumulating the benchmark results.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
boost::thread_group ThreadGroup
Po::typed_value< int32_t > * i32(int32_t *v=0)
Helpers to compose init policies; allow to combine two policies into one.
Manages a collection of program options.
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Importing boost::thread and boost::thread_group into the Hypertable namespace.
void operator()(double x)
Po::typed_value< Strings > * strs(Strings *v=0)
A Policy class for extending command line options.
The Stopwatch class measures elapsed time between instantiation (or a call to start) and a call to st...
Accumulates min, max, mean and stdev of the test results; based on the Welford method for numerical s...
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
System information and statistics based on libsigar.
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
Helper class wrapping the invocation of a single test function.
void print_proc_stat()
Prints statistics about the current process.
void serial_run(FunT fun, size_t n, bool proc_stat=false)
Runs a test serially n times in a row while accumulating the benchmark results.
static void init_options()