summaryrefslogtreecommitdiff
path: root/benchmark/api
diff options
context:
space:
mode:
authorJuha Alanen <juha.alanen@mapbox.com>2020-04-05 22:10:32 +0300
committerJuha Alanen <juha.alanen@mapbox.com>2020-04-15 19:11:28 +0300
commit8c499c9955f6acfa1b33ff315db530335296f778 (patch)
tree46a8acb16f9472ab6943694e8e752f3789c8eb8a /benchmark/api
parent5d8ad4c99e0dee2af2ff8bf47333db3dda71321a (diff)
downloadqtlocation-mapboxgl-8c499c9955f6acfa1b33ff315db530335296f778.tar.gz
[benchmark] Add new benchmark for rendering a map
Diffstat (limited to 'benchmark/api')
-rw-r--r--benchmark/api/render.benchmark.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp
index f192e7d3a3..04d96a40fd 100644
--- a/benchmark/api/render.benchmark.cpp
+++ b/benchmark/api/render.benchmark.cpp
@@ -34,7 +34,7 @@ public:
util::RunLoop loop;
};
-static void prepare(Map& map, optional<std::string> json = {}) {
+void prepare(Map& map, optional<std::string> json = nullopt) {
map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan
@@ -42,6 +42,14 @@ static void prepare(Map& map, optional<std::string> json = {}) {
map.getStyle().addImage(std::make_unique<style::Image>("test-icon", std::move(image), 1.0));
}
+void prepare_map2(Map& map, optional<std::string> json = nullopt) {
+ map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json"));
+ map.jumpTo(CameraOptions().withCenter(LatLng{41.379800, 2.176810}).withZoom(15.0)); // Barcelona
+
+ auto image = decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png"));
+ map.getStyle().addImage(std::make_unique<style::Image>("test-icon", std::move(image), 1.0));
+}
+
} // end namespace
static void API_renderStill_reuse_map(::benchmark::State& state) {
@@ -52,7 +60,7 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
prepare(map);
- while (state.KeepRunning()) {
+ for (auto _ : state) {
frontend.render(map);
}
}
@@ -65,7 +73,7 @@ static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json"));
- while (state.KeepRunning()) {
+ for (auto _ : state) {
frontend.render(map);
}
}
@@ -77,7 +85,7 @@ static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
- while (state.KeepRunning()) {
+ for (auto _ : state) {
prepare(map, { "{}" });
frontend.render(map);
prepare(map);
@@ -88,7 +96,7 @@ static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
static void API_renderStill_recreate_map(::benchmark::State& state) {
RenderBenchmark bench;
- while (state.KeepRunning()) {
+ for (auto _ : state) {
HeadlessFrontend frontend { size, pixelRatio };
Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
@@ -98,6 +106,20 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
}
}
+static void API_renderStill_recreate_map_2(::benchmark::State& state) {
+ RenderBenchmark bench;
+
+ for (auto _ : state) {
+ HeadlessFrontend frontend{size, pixelRatio};
+ Map map{frontend,
+ MapObserver::nullObserver(),
+ MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
+ ResourceOptions().withCachePath(cachePath).withAccessToken("foobar")};
+ prepare_map2(map);
+ frontend.render(map);
+ }
+}
+
static void API_renderStill_multiple_sources(::benchmark::State& state) {
using namespace mbgl::style;
RenderBenchmark bench;
@@ -124,13 +146,14 @@ static void API_renderStill_multiple_sources(::benchmark::State& state) {
}
}
- while (state.KeepRunning()) {
+ for (auto _ : state) {
frontend.render(map);
}
}
-BENCHMARK(API_renderStill_reuse_map);
-BENCHMARK(API_renderStill_reuse_map_formatted_labels);
-BENCHMARK(API_renderStill_reuse_map_switch_styles);
-BENCHMARK(API_renderStill_recreate_map);
-BENCHMARK(API_renderStill_multiple_sources);
+BENCHMARK(API_renderStill_reuse_map)->Unit(benchmark::kMillisecond);
+BENCHMARK(API_renderStill_reuse_map_formatted_labels)->Unit(benchmark::kMillisecond);
+BENCHMARK(API_renderStill_reuse_map_switch_styles)->Unit(benchmark::kMillisecond);
+BENCHMARK(API_renderStill_recreate_map)->Unit(benchmark::kMillisecond);
+BENCHMARK(API_renderStill_recreate_map_2)->Unit(benchmark::kMillisecond);
+BENCHMARK(API_renderStill_multiple_sources)->Unit(benchmark::kMillisecond);