#ifndef ISAAC_BENCH_COMMON_HPP_ #define ISAAC_BENCH_COMMON_HPP_ #include #include template struct int_{}; template std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_ ) { out << std::get< std::tuple_size::value-Pos >(t) << ','; return print_tuple(out, t, int_()); } template std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<1> ) { return out << std::get::value-1>(t); } template std::ostream& operator<<(std::ostream& out, const std::tuple& t) { print_tuple(out, t, int_()); return out; } int ceil(int N, int pad) { return (N%pad==0)?N:(N+pad-1)/pad*pad; } std::vector create_log_range(int min, int max, int N, int pad) { std::vector res(N); for(int i = 0 ; i < N ; ++i) { res[i] = static_cast(std::exp(std::log(min) + (float)(std::log(max) - std::log(min))*i/N)); res[i] = ceil(res[i], pad); } return res; } std::vector create_full_range(int min, int max, int pad) { std::vector N; for(int i = ceil(min, pad) ; i < ceil(max, pad) ; i+=pad) N.push_back(i); return N; } template T median(std::vector x) { size_t size = x.size(); std::sort(x.begin(), x.end()); if (size % 2 == 0) return (x[size / 2 - 1] + x[size / 2]) / 2; else return x[size / 2]; } template T min(std::vector x) { return *std::min_element(x.begin(), x.end()); } template T mean(std::vector x) { T res = 0; int N = x.size(); for(int i = 0 ; i < N ; ++i) res += x[i]; return res/N; } class Timer { typedef std::chrono::high_resolution_clock high_resolution_clock; typedef std::chrono::nanoseconds nanoseconds; public: explicit Timer(bool run = false) { if (run) start(); } void start() { _start = high_resolution_clock::now(); } nanoseconds get() const { return std::chrono::duration_cast(high_resolution_clock::now() - _start); } private: high_resolution_clock::time_point _start; }; #endif