blob: 4269f8e16946b2331d8bc00d91a0b3fe6410eb4c (
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
|
#include <benchmark/benchmark.h>
#include <mbgl/style/filter.hpp>
#include <mbgl/style/filter_evaluator.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <rapidjson/document.h>
#include <map>
using namespace mbgl;
typedef std::multimap<std::string, Value> Properties;
style::Filter parse(const char* expression) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
doc.Parse<0>(expression);
return style::conversion::convertFilter(doc).get<style::Filter>();
}
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") } };
while (state.KeepRunning()) {
filter(FeatureType::Unknown, [&] (const std::string& key) -> optional<Value> {
auto it = properties.find(key);
if (it == properties.end())
return {};
return it->second;
});
}
}
BENCHMARK(Parse_Filter);
BENCHMARK(Parse_EvaluateFilter);
|