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 --- Makefile | 2 +- benchmark/function/camera_function.benchmark.cpp | 69 ++++++++++++++++++++ .../function/composite_function.benchmark.cpp | 76 ++++++++++++++++++++++ benchmark/function/source_function.benchmark.cpp | 70 ++++++++++++++++++++ .../mbgl/benchmark/stub_geometry_tile_feature.hpp | 41 ++++++++++++ cmake/benchmark-files.cmake | 6 ++ platform/linux/config.cmake | 2 +- platform/macos/config.cmake | 2 +- 8 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 benchmark/function/camera_function.benchmark.cpp create mode 100644 benchmark/function/composite_function.benchmark.cpp create mode 100644 benchmark/function/source_function.benchmark.cpp create mode 100644 benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp diff --git a/Makefile b/Makefile index 88127011cc..e96c2d251e 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ run-test-%: test run-benchmark: run-benchmark-. run-benchmark-%: benchmark - $(MACOS_OUTPUT_PATH)/$(BUILDTYPE)/mbgl-benchmark --benchmark_filter=$* + $(MACOS_OUTPUT_PATH)/$(BUILDTYPE)/mbgl-benchmark --benchmark_filter=$* ${BENCHMARK_ARGS} .PHONY: node-benchmark node-benchmark: $(MACOS_PROJ_PATH) diff --git a/benchmark/function/camera_function.benchmark.cpp b/benchmark/function/camera_function.benchmark.cpp new file mode 100644 index 0000000000..965b004cb5 --- /dev/null +++ b/benchmark/function/camera_function.benchmark.cpp @@ -0,0 +1,69 @@ +#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(24.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_CameraFunction(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_CameraFunction(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()) { + float z = 24.0f * static_cast(rand() % 100) / 100; + function->evaluate(z); + } + + state.SetLabel(std::to_string(stopCount).c_str()); +} + +BENCHMARK(Parse_CameraFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + +BENCHMARK(Evaluate_CameraFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + + diff --git a/benchmark/function/composite_function.benchmark.cpp b/benchmark/function/composite_function.benchmark.cpp new file mode 100644 index 0000000000..f04b6c7073 --- /dev/null +++ b/benchmark/function/composite_function.benchmark.cpp @@ -0,0 +1,76 @@ +#include + +#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 outerStop = 0; outerStop < stopCount; outerStop++) { + for (size_t innerStop = 0; innerStop < stopCount; innerStop++) { + std::string zoom = std::to_string(24.0f / stopCount * outerStop); + std::string value = std::to_string(100.0f / stopCount * innerStop); + + if (stops.size() > 1) stops += ","; + stops += R"([{"zoom":)" + zoom + R"(,"value":)" + value + "}, " + value + "]"; + } + } + stops += "]"; + + doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})"); + return doc; +} + +static void Parse_CompositeFunction(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_CompositeFunction(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()) { + float z = 24.0f * static_cast(rand() % 100) / 100; + function->evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast(rand() % 100) } }), -1.0f); + } + + state.SetLabel(std::to_string(stopCount).c_str()); +} + +BENCHMARK(Parse_CompositeFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + +BENCHMARK(Evaluate_CompositeFunction) + ->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12); + + 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); + + diff --git a/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp b/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp new file mode 100644 index 0000000000..e27aeeb48b --- /dev/null +++ b/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include + +using namespace mbgl; + +class StubGeometryTileFeature : public GeometryTileFeature { +public: + StubGeometryTileFeature(PropertyMap properties_) + : properties(std::move(properties_)) { + } + + StubGeometryTileFeature(optional id_, FeatureType type_, GeometryCollection geometry_, PropertyMap properties_) + : properties(std::move(properties_)), + id(std::move(id_)), + type(type_), + geometry(std::move(geometry_)) { + } + + PropertyMap properties; + optional id; + FeatureType type = FeatureType::Point; + GeometryCollection geometry; + + FeatureType getType() const override { + return type; + } + + optional getID() const override { + return id; + } + + optional getValue(const std::string& key) const override { + return properties.count(key) ? properties.at(key) : optional(); + } + + GeometryCollection getGeometries() const override { + return geometry; + } +}; diff --git a/cmake/benchmark-files.cmake b/cmake/benchmark-files.cmake index f17d95941d..9161209128 100644 --- a/cmake/benchmark-files.cmake +++ b/cmake/benchmark-files.cmake @@ -5,6 +5,11 @@ set(MBGL_BENCHMARK_FILES benchmark/api/query.benchmark.cpp benchmark/api/render.benchmark.cpp + # function + benchmark/function/camera_function.benchmark.cpp + benchmark/function/composite_function.benchmark.cpp + benchmark/function/source_function.benchmark.cpp + # include/mbgl benchmark/include/mbgl/benchmark.hpp @@ -18,6 +23,7 @@ set(MBGL_BENCHMARK_FILES # src/mbgl/benchmark benchmark/src/mbgl/benchmark/benchmark.cpp + benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp # util benchmark/util/dtoa.benchmark.cpp diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake index 3aa1fdbbfc..badbde408f 100644 --- a/platform/linux/config.cmake +++ b/platform/linux/config.cmake @@ -8,7 +8,7 @@ mason_use(libpng VERSION 1.6.25) mason_use(libjpeg-turbo VERSION 1.5.0) mason_use(webp VERSION 0.5.1) mason_use(gtest VERSION 1.8.0${MASON_CXXABI_SUFFIX}) -mason_use(benchmark VERSION 1.0.0-1) +mason_use(benchmark VERSION 1.2.0) mason_use(icu VERSION 58.1-min-size) # Link with libuv. This is not part of loop-uv.cmake because loop-uv.cmake is also diff --git a/platform/macos/config.cmake b/platform/macos/config.cmake index 86c54b612c..1d471e1a8b 100644 --- a/platform/macos/config.cmake +++ b/platform/macos/config.cmake @@ -3,7 +3,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) mason_use(glfw VERSION 2017-07-13-67c9155) mason_use(boost_libprogram_options VERSION 1.62.0) mason_use(gtest VERSION 1.8.0) -mason_use(benchmark VERSION 1.0.0-1) +mason_use(benchmark VERSION 1.2.0) mason_use(icu VERSION 58.1-min-size) include(cmake/loop-darwin.cmake) -- cgit v1.2.1