summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-06-01 18:06:26 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-06-06 13:50:55 +0200
commit0fe60d398e563fe01a3aabab1f39b733883c4e71 (patch)
tree4ef7c3de32883544404cb70df9d866f4c73b1ffe /benchmark
parentd3fe7984930fe7636d9dc36c8aa4c7ec3e891e49 (diff)
downloadqtlocation-mapboxgl-0fe60d398e563fe01a3aabab1f39b733883c4e71.tar.gz
[build] add benchmark target
Diffstat (limited to 'benchmark')
-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
5 files changed, 177 insertions, 0 deletions
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