summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--benchmark/benchmark.gypi87
-rw-r--r--benchmark/include/mbgl/benchmark.hpp7
-rw-r--r--benchmark/parse/filter.cpp65
-rw-r--r--benchmark/src/main.cpp5
-rw-r--r--benchmark/src/mbgl/benchmark/benchmark.cpp13
-rwxr-xr-xconfigure1
-rw-r--r--platform/linux/platform.gyp14
-rw-r--r--platform/linux/scripts/configure.sh1
-rw-r--r--platform/osx/platform.gyp14
-rw-r--r--platform/osx/scripts/configure.sh1
11 files changed, 209 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 0e23b47af8..ad1ebba793 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ CONFIG_DEPENDENCIES = .mason/mason configure
# Depend on gyp includes plus directories, so that projects are regenerated when
# files are added or removed.
-GYP_DEPENDENCIES = mbgl.gypi test/test.gypi bin/*.gypi $(shell find src include -type d) node_modules
+GYP_DEPENDENCIES = mbgl.gypi test/test.gypi benchmark/benchmark.gypi bin/*.gypi $(shell find src include -type d) node_modules
#### OS X targets ##############################################################
diff --git a/benchmark/benchmark.gypi b/benchmark/benchmark.gypi
new file mode 100644
index 0000000000..011ac16584
--- /dev/null
+++ b/benchmark/benchmark.gypi
@@ -0,0 +1,87 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'benchmark-lib',
+ 'type': 'static_library',
+ 'standalone_static_library': 1,
+ 'hard_dependency': 1,
+ 'dependencies': [
+ 'core',
+ ],
+
+ 'include_dirs': [
+ '../include',
+ '../src',
+ '../platform/default',
+ 'include',
+ 'src',
+ ],
+
+ 'sources': [
+ 'parse/filter.cpp',
+
+
+ 'src/mbgl/benchmark/benchmark.cpp'
+ ],
+
+ 'variables': {
+ 'cflags_cc': [
+ '<@(benchmark_cflags)',
+ '<@(rapidjson_cflags)',
+ ],
+ 'ldflags': [
+ '<@(benchmark_ldflags)',
+ ],
+ 'libraries': [
+ '<@(benchmark_static_libs)',
+ ],
+ },
+
+ 'conditions': [
+ ['OS == "mac"', {
+ 'xcode_settings': {
+ 'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ],
+ },
+ }, {
+ 'cflags_cc': [ '<@(cflags_cc)' ],
+ }],
+ ],
+ 'link_settings': {
+ 'conditions': [
+ ['OS == "mac"', {
+ 'libraries': [ '<@(libraries)' ],
+ 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)' ] }
+ }, {
+ 'libraries': [ '<@(libraries)', '<@(ldflags)' ],
+ }]
+ ],
+ },
+
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ 'include',
+ ],
+
+ # Force the linker to include all the objects from the lib-benchmark archive. Otherwise they'd
+ # be discarded because there are no undefined symbols to pull them in, and the resulting
+ # executable would run zero tests.
+
+ 'conditions': [
+ ['OS == "mac"', {
+ 'xcode_settings': {
+ 'OTHER_LDFLAGS': [
+ '-Wl,-force_load,<(PRODUCT_DIR)/libbenchmark-lib.a',
+ ],
+ }
+ }, {
+ 'link_settings': {
+ 'ldflags': [
+ '-Wl,-whole-archive <(PRODUCT_DIR)/libbenchmark-lib.a -Wl,-no-whole-archive',
+ ],
+ },
+ }],
+ ],
+ },
+ },
+ ]
+}
diff --git a/benchmark/include/mbgl/benchmark.hpp b/benchmark/include/mbgl/benchmark.hpp
new file mode 100644
index 0000000000..1a9904de51
--- /dev/null
+++ b/benchmark/include/mbgl/benchmark.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace mbgl {
+
+int runBenchmark(int argc, char* argv[]);
+
+} // namespace mbgl
diff --git a/benchmark/parse/filter.cpp b/benchmark/parse/filter.cpp
new file mode 100644
index 0000000000..9e47bcaca9
--- /dev/null
+++ b/benchmark/parse/filter.cpp
@@ -0,0 +1,65 @@
+#include <benchmark/benchmark.h>
+
+#include <mbgl/style/filter.hpp>
+#include <mbgl/style/filter_evaluator.hpp>
+#include <mbgl/style/parser.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
+
+#include <rapidjson/document.h>
+
+#include <map>
+
+using namespace mbgl;
+
+typedef std::multimap<std::string, Value> Properties;
+
+class StubFeature : public GeometryTileFeature {
+public:
+ inline StubFeature(const Properties& properties_, FeatureType type_)
+ : properties(properties_), type(type_) {
+ }
+
+ optional<Value> getValue(const std::string& key) const override {
+ auto it = properties.find(key);
+ if (it == properties.end())
+ return optional<Value>();
+ return it->second;
+ }
+
+ FeatureType getType() const override {
+ return type;
+ }
+
+ GeometryCollection getGeometries() const override {
+ return GeometryCollection();
+ }
+
+private:
+ const Properties properties;
+ FeatureType type;
+};
+
+style::Filter parse(const char* expression) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
+ doc.Parse<0>(expression);
+ return style::parseFilter(doc);
+}
+
+static void Parse_Filter(benchmark::State& state) {
+ while (state.KeepRunning()) {
+ parse(R"FILTER(["==", "foo", "bar"])FILTER");
+ }
+}
+
+static void Parse_EvaluateFilter(benchmark::State& state) {
+ const style::Filter filter = parse(R"FILTER(["==", "foo", "bar"])FILTER");
+ const Properties properties = { { "foo", std::string("bar") } };
+ const StubFeature feature(properties, FeatureType::Unknown);
+
+ while (state.KeepRunning()) {
+ style::Filter::visit(filter, style::FilterEvaluator{ feature });
+ }
+}
+
+BENCHMARK(Parse_Filter);
+BENCHMARK(Parse_EvaluateFilter);
diff --git a/benchmark/src/main.cpp b/benchmark/src/main.cpp
new file mode 100644
index 0000000000..afe785140f
--- /dev/null
+++ b/benchmark/src/main.cpp
@@ -0,0 +1,5 @@
+#include <mbgl/benchmark.hpp>
+
+int main(int argc, char* argv[]) {
+ return mbgl::runBenchmark(argc, argv);
+}
diff --git a/benchmark/src/mbgl/benchmark/benchmark.cpp b/benchmark/src/mbgl/benchmark/benchmark.cpp
new file mode 100644
index 0000000000..d408e7c5e1
--- /dev/null
+++ b/benchmark/src/mbgl/benchmark/benchmark.cpp
@@ -0,0 +1,13 @@
+#include <mbgl/benchmark.hpp>
+
+#include <benchmark/benchmark.h>
+
+namespace mbgl {
+
+int runBenchmark(int argc, char* argv[]) {
+ ::benchmark::Initialize(&argc, argv);
+ ::benchmark::RunSpecifiedBenchmarks();
+ return 0;
+}
+
+} // namespace mbgl
diff --git a/configure b/configure
index 24b9642781..69acbde010 100755
--- a/configure
+++ b/configure
@@ -122,6 +122,7 @@ print_flags pixelmatch static_libs cflags ldflags
print_flags webp static_libs cflags ldflags
print_flags jni.hpp cflags
print_flags earcut cflags
+print_flags benchmark static_libs cflags ldflags
CONFIG+=" }
}
diff --git a/platform/linux/platform.gyp b/platform/linux/platform.gyp
index 98a1e253c9..7adf5337c4 100644
--- a/platform/linux/platform.gyp
+++ b/platform/linux/platform.gyp
@@ -14,6 +14,7 @@
'includes': [
'../../mbgl.gypi',
'../../test/test.gypi',
+ '../../benchmark/benchmark.gypi',
'../../bin/glfw.gypi',
'../../bin/render.gypi',
'../../bin/offline.gypi',
@@ -34,6 +35,19 @@
],
},
{
+ 'target_name': 'benchmark',
+ 'type': 'executable',
+
+ 'dependencies': [
+ 'benchmark-lib',
+ 'platform-lib',
+ ],
+
+ 'sources': [
+ '../../benchmark/src/main.cpp',
+ ],
+ },
+ {
'target_name': 'platform-lib',
'product_name': 'mbgl-platform-linux',
'type': 'static_library',
diff --git a/platform/linux/scripts/configure.sh b/platform/linux/scripts/configure.sh
index 0f74afc55f..8f041d589a 100644
--- a/platform/linux/scripts/configure.sh
+++ b/platform/linux/scripts/configure.sh
@@ -22,6 +22,7 @@ GTEST_VERSION=1.7.0${CXX11ABI:-}
PIXELMATCH_VERSION=0.9.0
WEBP_VERSION=0.5.0
EARCUT_VERSION=0.11
+BENCHMARK_VERSION=1.0.0
function print_opengl_flags {
CONFIG+=" 'opengl_cflags%': $(quote_flags $(pkg-config gl x11 --cflags)),"$LN
diff --git a/platform/osx/platform.gyp b/platform/osx/platform.gyp
index c3f94935d3..bbda61e7d9 100644
--- a/platform/osx/platform.gyp
+++ b/platform/osx/platform.gyp
@@ -8,6 +8,7 @@
'../../build/osx/config.gypi',
'../../mbgl.gypi',
'../../test/test.gypi',
+ '../../benchmark/benchmark.gypi',
'../../bin/glfw.gypi',
'../../bin/render.gypi',
'../../bin/offline.gypi',
@@ -27,6 +28,19 @@
],
},
{
+ 'target_name': 'benchmark',
+ 'type': 'executable',
+
+ 'dependencies': [
+ 'benchmark-lib',
+ 'platform-lib',
+ ],
+
+ 'sources': [
+ '../../benchmark/src/main.cpp',
+ ],
+ },
+ {
'target_name': 'platform-lib',
'product_name': 'mbgl-platform-osx',
'type': 'static_library',
diff --git a/platform/osx/scripts/configure.sh b/platform/osx/scripts/configure.sh
index 44cbea6f26..2952ec2535 100644
--- a/platform/osx/scripts/configure.sh
+++ b/platform/osx/scripts/configure.sh
@@ -15,3 +15,4 @@ RAPIDJSON_VERSION=1.0.2
GTEST_VERSION=1.7.0
PIXELMATCH_VERSION=0.9.0
EARCUT_VERSION=0.11
+BENCHMARK_VERSION=1.0.0