#include #include #include #include #include #include #include "performance_measure.hpp" extern void reference_evaluate(); std::map times; std::set tests; double total = 0; int call_count = 0; std::set& all_tests() { static std::set i; return i; } void add_new_test(test_info i) { all_tests().insert(i); } void set_call_count(int i) { call_count = i; } void show_help() { std::cout << "Specify on the command line which functions to test.\n" "Available options are:\n"; std::set::const_iterator i(all_tests().begin()), j(all_tests().end()); while(i != j) { std::cout << " --" << (*i).name << std::endl; ++i; } std::cout << "Or use --all to test everything." << std::endl; } void run_tests() { // Get time for empty proceedure: double reference_time = performance_measure(reference_evaluate); std::set::const_iterator i, j; for(i = tests.begin(), j = tests.end(); i != j; ++i) { set_call_count(1); std::cout << "Testing " << std::left << std::setw(40) << i->name << std::flush; double time = performance_measure(i->proc) - reference_time; time /= call_count; std::cout << std::setprecision(3) << std::scientific << time << std::endl; } } int main(int argc, const char** argv) { try{ if(argc >= 2) { for(int i = 1; i < argc; ++i) { if(std::strcmp(argv[i], "--help") == 0) { show_help(); } else if(std::strcmp(argv[i], "--all") == 0) { std::set::const_iterator a(all_tests().begin()), b(all_tests().end()); while(a != b) { tests.insert(*a); ++a; } } else { bool found = false; if((argv[i][0] == '-') && (argv[i][1] == '-')) { std::set::const_iterator a(all_tests().begin()), b(all_tests().end()); while(a != b) { if(std::strcmp(argv[i] + 2, (*a).name) == 0) { found = true; tests.insert(*a); break; } ++a; } } if(!found) { std::cerr << "Unknown option: " << argv[i] << std::endl; return 1; } } } run_tests(); } else { show_help(); } // // This is just to confuse the optimisers: // if(argc == 100000) { std::cerr << total << std::endl; } } catch(const std::exception& e) { std::cerr << e.what() << std::endl; } return 0; } void consume_result(double x) { // Do nothing proceedure, don't let whole program optimisation // optimise this away - doing so may cause false readings.... total += x; }