From e0f62c1680959ffa469841582ef6b732560b72f2 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Tue, 22 Aug 2017 16:23:27 -0400 Subject: Add {Source,CompositeCamera}Function benchmarks --- benchmark/function/source_function.benchmark.cpp | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 benchmark/function/source_function.benchmark.cpp (limited to 'benchmark/function/source_function.benchmark.cpp') diff --git a/benchmark/function/source_function.benchmark.cpp b/benchmark/function/source_function.benchmark.cpp new file mode 100644 index 0000000000..14e729eee2 --- /dev/null +++ b/benchmark/function/source_function.benchmark.cpp @@ -0,0 +1,70 @@ +#include + +#include + +#include + +#include +#include +#include + +#include + + +using namespace mbgl; +using namespace mbgl::style; + +static rapidjson::GenericDocument, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) { + rapidjson::GenericDocument, rapidjson::CrtAllocator> doc; + + std::string stops = "["; + for (size_t i = 0; i < stopCount; i++) { + std::string value = std::to_string(100.0f / stopCount * i); + if (stops.size() > 1) stops += ","; + stops += "[" + value + ", " + value + "]"; + } + stops += "]"; + + doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})"); + return doc; +} + +static void Parse_SourceFunction(benchmark::State& state) { + size_t stopCount = state.range(0); + + while (state.KeepRunning()) { + conversion::Error error; + state.PauseTiming(); + auto doc = createFunctionJSON(stopCount); + state.ResumeTiming(); + optional> result = conversion::convert, JSValue>(doc, error); + if (!result) { + state.SkipWithError(error.message.c_str()); + } + } + state.SetLabel(std::to_string(stopCount).c_str()); +} + +static void Evaluate_SourceFunction(benchmark::State& state) { + size_t stopCount = state.range(0); + auto doc = createFunctionJSON(stopCount); + conversion::Error error; + optional> function = conversion::convert, JSValue>(doc, error); + if (!function) { + state.SkipWithError(error.message.c_str()); + } + + while(state.KeepRunning()) { + function->evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast(rand() % 100) } }), -1.0f); + } + + state.SetLabel(std::to_string(stopCount).c_str()); +} + +BENCHMARK(Parse_SourceFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + +BENCHMARK(Evaluate_SourceFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + + -- cgit v1.2.1