diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-06-01 18:06:26 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-06-06 13:50:55 +0200 |
commit | 0fe60d398e563fe01a3aabab1f39b733883c4e71 (patch) | |
tree | 4ef7c3de32883544404cb70df9d866f4c73b1ffe /benchmark/parse | |
parent | d3fe7984930fe7636d9dc36c8aa4c7ec3e891e49 (diff) | |
download | qtlocation-mapboxgl-0fe60d398e563fe01a3aabab1f39b733883c4e71.tar.gz |
[build] add benchmark target
Diffstat (limited to 'benchmark/parse')
-rw-r--r-- | benchmark/parse/filter.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
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); |