benchmarks: helper class for running a sequence of tests

This commit is contained in:
Mickey Rose 2016-02-16 19:53:03 +01:00
parent 29c4f730eb
commit 2f303e4da4
5 changed files with 59 additions and 126 deletions

View file

@ -186,6 +186,34 @@ int run(T const& test_runner, std::string const& name)
return 0;
}
struct sequencer
{
sequencer(int argc, char** argv)
: exit_code_(0)
{
benchmark::handle_args(argc, argv, params_);
}
int done() const
{
return exit_code_;
}
template <typename Test, typename... Args>
sequencer & run(std::string const& name, Args && ...args)
{
// Test instance lifetime is confined to this function
Test test_runner(params_, std::forward<Args>(args)...);
// any failing test run will make exit code non-zero
exit_code_ |= benchmark::run(test_runner, name);
return *this; // allow chaining calls
}
protected:
mapnik::parameters params_;
int exit_code_;
};
}
#endif // __MAPNIK_BENCH_FRAMEWORK_HPP__

View file

@ -359,62 +359,21 @@ public:
int main(int argc, char** argv)
{
int return_value = 0;
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
{
test4 test_runner4(params);
return_value = return_value | run(test_runner4,"calloc");
}
{
test1 test_runner(params);
return_value = return_value | run(test_runner,"malloc/memcpy");
}
{
test1b test_runner(params);
return_value = return_value | run(test_runner,"malloc/memset");
}
{
test1c test_runner(params);
return_value = return_value | run(test_runner,"operator new/std::fill");
}
{
test2 test_runner(params);
return_value = return_value | run(test_runner,"operator new/memcpy");
}
{
test3 test_runner(params);
return_value = return_value | run(test_runner,"vector(N)");
}
{
test3b test_runner(params);
return_value = return_value | run(test_runner,"vector/resize");
}
{
test3c test_runner(params);
return_value = return_value | run(test_runner,"vector/assign");
}
{
test3d test_runner(params);
return_value = return_value | run(test_runner,"deque(N)");
}
{
test5 test_runner(params);
return_value = return_value | run(test_runner,"std::string range");
}
{
test5b test_runner(params);
return_value = return_value | run(test_runner,"std::string &[0]");
}
{
test6 test_runner(params);
return_value = return_value | run(test_runner,"valarray");
}
return benchmark::sequencer(argc, argv)
.run<test4>("calloc")
.run<test1>("malloc/memcpy")
.run<test1b>("malloc/memset")
.run<test1c>("operator new/std::fill")
.run<test2>("operator new/memcpy")
.run<test3>("vector(N)")
.run<test3b>("vector/resize")
.run<test3c>("vector/assign")
.run<test3d>("deque(N)")
.run<test5>("std::string range")
.run<test5b>("std::string &[0]")
.run<test6>("valarray")
#if BOOST_VERSION >= 105400
{
test7 test_runner(params);
return_value = return_value | run(test_runner,"static_vector");
}
.run<test7>("static_vector")
#endif
return return_value;
.done();
}

View file

@ -73,16 +73,8 @@ public:
int main(int argc, char** argv)
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
int return_value = 0;
{
test_static test_runner(params);
return_value = return_value | run(test_runner,"static_cast");
}
{
test_numeric test_runner(params);
return_value = return_value | run(test_runner,"numeric_cast");
}
return return_value;
return benchmark::sequencer(argc, argv)
.run<test_static>("static_cast")
.run<test_numeric>("numeric_cast")
.done();
}

View file

@ -51,30 +51,10 @@ int main(int argc, char** argv)
mapnik::box2d<double> z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298);
// bbox for 16/10491/22911.png
mapnik::box2d<double> z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214);
int return_value = 0;
{
test test_runner(params,
"benchmark/data/polygon_rendering_clip.xml",
z1);
return_value = return_value | run(test_runner,"polygon clip render z1");
}
{
test test_runner(params,
"benchmark/data/polygon_rendering_no_clip.xml",
z1);
return_value = return_value | run(test_runner,"polygon noclip render z1");
}
{
test test_runner(params,
"benchmark/data/polygon_rendering_clip.xml",
z16);
return_value = return_value | run(test_runner,"polygon clip render z16");
}
{
test test_runner(params,
"benchmark/data/polygon_rendering_no_clip.xml",
z16);
return_value = return_value | run(test_runner,"polygon noclip render z16");
}
return return_value;
return benchmark::sequencer(argc, argv)
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
.run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1)
.run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
.done();
}

View file

@ -59,42 +59,16 @@ public:
// echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857
int main(int argc, char** argv)
{
mapnik::parameters params;
benchmark::handle_args(argc,argv,params);
mapnik::box2d<double> from(-180,-80,180,80);
mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
std::string from_str("+init=epsg:4326");
std::string to_str("+init=epsg:3857");
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over");
int return_value = 0;
test test_runner(params,
from_str,
to_str,
from,
to,
true);
return_value = return_value | run(test_runner,"lonlat->merc epsg");
test test_runner2(params,
from_str2,
to_str2,
from,
to,
true);
return_value = return_value | run(test_runner2,"lonlat->merc literal");
test test_runner3(params,
to_str,
from_str,
to,
from,
true);
return_value = return_value | run(test_runner3,"merc->lonlat epsg");
test test_runner4(params,
to_str2,
from_str2,
to,
from,
true);
return_value = return_value | run(test_runner4,"merc->lonlat literal");
return return_value;
return benchmark::sequencer(argc, argv)
.run<test>("lonlat->merc epsg", from_str, to_str, from, to, true)
.run<test>("lonlat->merc literal", from_str2, to_str2, from, to, true)
.run<test>("merc->lonlat epsg", to_str, from_str, to, from, true)
.run<test>("merc->lonlat literal", to_str2, from_str2, to, from, true)
.done();
}