summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAnand Thakker <anandthakker@users.noreply.github.com>2017-08-29 10:03:57 -0400
committerGitHub <noreply@github.com>2017-08-29 10:03:57 -0400
commitd436bcd56b2a2b68195f546c11919dd46e8049ce (patch)
treec9eccd5a1248e5128a47e4f643f5afd2c7621773 /benchmark
parenta2712f6fa439af976f7c17685b78340cb14d67a1 (diff)
downloadqtlocation-mapboxgl-d436bcd56b2a2b68195f546c11919dd46e8049ce.tar.gz
Add {Source,CompositeCamera}Function benchmarks (#9838)
Diffstat (limited to 'benchmark')
-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
4 files changed, 256 insertions, 0 deletions
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;
+ }
+};