#ifndef __MAPNIK_BENCH_FRAMEWORK_HPP__ #define __MAPNIK_BENCH_FRAMEWORK_HPP__ // mapnik #include #include // stl #include #include #include #include #include #include #include namespace benchmark { class test_case { protected: mapnik::parameters params_; std::size_t threads_; std::size_t iterations_; public: test_case(mapnik::parameters const& params) : params_(params), threads_(*params.get("threads",0)), iterations_(*params.get("iterations",0)) {} std::size_t threads() const { return threads_; } std::size_t iterations() const { return iterations_; } virtual bool validate() const = 0; virtual bool operator()() const = 0; virtual ~test_case() {} }; void handle_args(int argc, char** argv, mapnik::parameters & params) { if (argc > 0) { for (int i=1;i int run(T const& test_runner, std::string const& name) { try { if (!test_runner.validate()) { std::clog << "test did not validate: " << name << "\n"; return -1; } // run test once before timing // if it returns false then we'll abort timing if (test_runner()) { std::chrono::high_resolution_clock::time_point start; std::chrono::high_resolution_clock::duration elapsed; std::stringstream s; s << name << ":" << std::setw(45 - (int)s.tellp()) << std::right << " t:" << test_runner.threads() << " i:" << test_runner.iterations(); if (test_runner.threads() > 0) { using thread_group = std::vector >; using value_type = thread_group::value_type; thread_group tg; for (std::size_t i=0;ijoinable()) t->join();}); elapsed = std::chrono::high_resolution_clock::now() - start; } else { start = std::chrono::high_resolution_clock::now(); test_runner(); elapsed = std::chrono::high_resolution_clock::now() - start; } s << std::setw(65 - (int)s.tellp()) << std::right << std::chrono::duration_cast(elapsed).count() << " milliseconds\n"; std::clog << s.str(); } return 0; } catch (std::exception const& ex) { std::clog << "test runner did not complete: " << ex.what() << "\n"; return -1; } return 0; } } #endif // __MAPNIK_BENCH_FRAMEWORK_HPP__