// Let Catch provide main(): #define CATCH_CONFIG_MAIN #define CATCH_CONFIG_ENABLE_BENCHMARKING #include #include std::vector generate_random_numbers(int n, int min, int max) { std::srand(std::time(nullptr)); std::vector v(n); for (int i = 0; i < n; ++i) v[i] = min + std::rand() / ((RAND_MAX + 1u)/max); return v; } TEST_CASE( "Simple test" ) { std::vector v = { 1, 2, 3, 1}; REQUIRE( performance_measuring::count_on_the_way(v) == 2 ); REQUIRE( performance_measuring::min_element_and_count(v) == 2 ); REQUIRE( performance_measuring::sort_and_upper_bound(v) == 2 ); } TEST_CASE("Benchmarking") { std::vector v = generate_random_numbers(10000, 0, 1000); BENCHMARK("count_on_the_way 10k") { return performance_measuring::count_on_the_way(v); }; BENCHMARK("min_element_and_count 10k") { return performance_measuring::min_element_and_count(v); }; BENCHMARK("sort_and_upper_bound 10k") { return performance_measuring::sort_and_upper_bound(v); }; }