[build] add benchmark target
This commit is contained in:
2
Makefile
2
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 ##############################################################
|
||||
|
||||
|
||||
87
benchmark/benchmark.gypi
Normal file
87
benchmark/benchmark.gypi
Normal file
@@ -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',
|
||||
],
|
||||
},
|
||||
}],
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
7
benchmark/include/mbgl/benchmark.hpp
Normal file
7
benchmark/include/mbgl/benchmark.hpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
int runBenchmark(int argc, char* argv[]);
|
||||
|
||||
} // namespace mbgl
|
||||
65
benchmark/parse/filter.cpp
Normal file
65
benchmark/parse/filter.cpp
Normal file
@@ -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);
|
||||
5
benchmark/src/main.cpp
Normal file
5
benchmark/src/main.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <mbgl/benchmark.hpp>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return mbgl::runBenchmark(argc, argv);
|
||||
}
|
||||
13
benchmark/src/mbgl/benchmark/benchmark.cpp
Normal file
13
benchmark/src/mbgl/benchmark/benchmark.cpp
Normal file
@@ -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
|
||||
1
configure
vendored
1
configure
vendored
@@ -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+=" }
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
'includes': [
|
||||
'../../mbgl.gypi',
|
||||
'../../test/test.gypi',
|
||||
'../../benchmark/benchmark.gypi',
|
||||
'../../bin/glfw.gypi',
|
||||
'../../bin/render.gypi',
|
||||
'../../bin/offline.gypi',
|
||||
@@ -33,6 +34,19 @@
|
||||
'../../test/src/main.cpp',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'benchmark',
|
||||
'type': 'executable',
|
||||
|
||||
'dependencies': [
|
||||
'benchmark-lib',
|
||||
'platform-lib',
|
||||
],
|
||||
|
||||
'sources': [
|
||||
'../../benchmark/src/main.cpp',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'platform-lib',
|
||||
'product_name': 'mbgl-platform-linux',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
@@ -26,6 +27,19 @@
|
||||
'../../test/src/main.cpp',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'benchmark',
|
||||
'type': 'executable',
|
||||
|
||||
'dependencies': [
|
||||
'benchmark-lib',
|
||||
'platform-lib',
|
||||
],
|
||||
|
||||
'sources': [
|
||||
'../../benchmark/src/main.cpp',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'platform-lib',
|
||||
'product_name': 'mbgl-platform-osx',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user