benchmark: number tests, allow dry-run to get test idx #, and allow passing args to only run specific tests

This commit is contained in:
Dane Springmeyer 2013-01-27 17:25:58 -08:00
parent cb49d9be81
commit 430e3d3406

View file

@ -11,6 +11,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>
#include <set>
// boost // boost
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -25,13 +26,29 @@
using namespace boost::chrono; using namespace boost::chrono;
using namespace mapnik; using namespace mapnik;
static unsigned test_num = 1;
static bool dry_run = false;
static std::set<int> test_set;
typedef process_cpu_clock clock_type; typedef process_cpu_clock clock_type;
typedef clock_type::duration dur; typedef clock_type::duration dur;
template <typename T> template <typename T>
void benchmark(T test, std::string const& name) void benchmark(T test, std::string const& name)
{ {
if (!test.validate()) throw std::runtime_error(std::string("test did not validate: ") + name); bool should_run_test = true;
if (!test_set.empty()) {
should_run_test = test_set.find(test_num) != test_set.end();
}
if (should_run_test) {
if (!test.validate()) {
std::clog << "test did not validate: " << name << "\n";
//throw std::runtime_error(std::string("test did not validate: ") + name);
}
if (dry_run) {
std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "")
<< name << "\n";
} else {
process_cpu_clock::time_point start; process_cpu_clock::time_point start;
dur elapsed; dur elapsed;
if (test.threads_ > 0) { if (test.threads_ > 0) {
@ -48,10 +65,13 @@ void benchmark(T test, std::string const& name)
test(); test();
elapsed = process_cpu_clock::now() - start; elapsed = process_cpu_clock::now() - start;
} }
std::clog << (test.threads_ ? "threaded -> ": "") std::clog << test_num << ") " << (test.threads_ ? "threaded -> ": "")
<< name << ": " << name << ": "
<< boost::chrono::duration_cast<milliseconds>(elapsed) << "\n"; << boost::chrono::duration_cast<milliseconds>(elapsed) << "\n";
} }
}
test_num++;
}
bool compare_images(std::string const& src_fn,std::string const& dest_fn) bool compare_images(std::string const& src_fn,std::string const& dest_fn)
{ {
@ -249,11 +269,25 @@ struct test5
}; };
int main( int, char*[] ) int main( int argc, char** argv)
{ {
if (argc > 0) {
for (int i=0;i<argc;++i) {
std::string opt(argv[i]);
if (opt == "-d" || opt == "--dry-run") {
dry_run = true;
} else if (opt[0] != '-') {
int arg;
if (mapnik::util::string2int(opt,arg)) {
test_set.insert(arg);
}
}
}
}
try try
{ {
std::cout << "starting benchmark…\n"; std::cout << "starting benchmark…\n";
{ {
test1 runner(100); test1 runner(100);
benchmark(runner,"encoding blank image as png"); benchmark(runner,"encoding blank image as png");