summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--benchmark/function/camera_function.benchmark.cpp69
-rw-r--r--benchmark/function/composite_function.benchmark.cpp76
-rw-r--r--benchmark/function/source_function.benchmark.cpp70
-rw-r--r--benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp41
-rw-r--r--cmake/benchmark-files.cmake6
-rw-r--r--platform/linux/config.cmake2
-rw-r--r--platform/macos/config.cmake2
8 files changed, 265 insertions, 3 deletions
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..1f8fe4579f
--- /dev/null
+++ b/benchmark/function/camera_function.benchmark.cpp
@@ -0,0 +1,69 @@
+#include <benchmark/benchmark.h>
+
+#include <mbgl/style/function/source_function.hpp>
+
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/function.hpp>
+
+#include <rapidjson/document.h>
+
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, 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 + "}");
+ 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<CameraFunction<float>> result = conversion::convert<CameraFunction<float>, 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<CameraFunction<float>> function = conversion::convert<CameraFunction<float>, JSValue>(doc, error);
+ if (!function) {
+ state.SkipWithError(error.message.c_str());
+ }
+
+ while(state.KeepRunning()) {
+ float z = 24.0f * static_cast<float>(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 <benchmark/benchmark.h>
+
+#include <mbgl/benchmark/stub_geometry_tile_feature.hpp>
+
+#include <mbgl/style/function/composite_exponential_stops.hpp>
+#include <mbgl/style/function/composite_function.hpp>
+
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/function.hpp>
+
+#include <rapidjson/document.h>
+
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, 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<CompositeFunction<float>> result = conversion::convert<style::CompositeFunction<float>, 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<CompositeFunction<float>> function = conversion::convert<CompositeFunction<float>, JSValue>(doc, error);
+ if (!function) {
+ state.SkipWithError(error.message.c_str());
+ }
+
+ while(state.KeepRunning()) {
+ float z = 24.0f * static_cast<float>(rand() % 100) / 100;
+ function->evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(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 <benchmark/benchmark.h>
+
+#include <mbgl/benchmark/stub_geometry_tile_feature.hpp>
+
+#include <mbgl/style/function/source_function.hpp>
+
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/function.hpp>
+
+#include <rapidjson/document.h>
+
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, 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<SourceFunction<float>> result = conversion::convert<SourceFunction<float>, 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<SourceFunction<float>> function = conversion::convert<SourceFunction<float>, JSValue>(doc, error);
+ if (!function) {
+ state.SkipWithError(error.message.c_str());
+ }
+
+ while(state.KeepRunning()) {
+ function->evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(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 <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/util/feature.hpp>
+
+using namespace mbgl;
+
+class StubGeometryTileFeature : public GeometryTileFeature {
+public:
+ StubGeometryTileFeature(PropertyMap properties_)
+ : properties(std::move(properties_)) {
+ }
+
+ StubGeometryTileFeature(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, PropertyMap properties_)
+ : properties(std::move(properties_)),
+ id(std::move(id_)),
+ type(type_),
+ geometry(std::move(geometry_)) {
+ }
+
+ PropertyMap properties;
+ optional<FeatureIdentifier> id;
+ FeatureType type = FeatureType::Point;
+ GeometryCollection geometry;
+
+ FeatureType getType() const override {
+ return type;
+ }
+
+ optional<FeatureIdentifier> getID() const override {
+ return id;
+ }
+
+ optional<Value> getValue(const std::string& key) const override {
+ return properties.count(key) ? properties.at(key) : optional<Value>();
+ }
+
+ 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)