blob: 9e47bcaca9b7c845fb497f85ab5e5d64b3a60794 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);
|