From 8c499c9955f6acfa1b33ff315db530335296f778 Mon Sep 17 00:00:00 2001 From: Juha Alanen Date: Sun, 5 Apr 2020 22:10:32 +0300 Subject: [benchmark] Add new benchmark for rendering a map --- benchmark/api/render.benchmark.cpp | 45 ++++++++++++++++++++++++++++--------- benchmark/fixtures/api/cache.db | Bin 1298432 -> 2654208 bytes 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'benchmark') 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 json = {}) { +void prepare(Map& map, optional 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 json = {}) { map.getStyle().addImage(std::make_unique("test-icon", std::move(image), 1.0)); } +void prepare_map2(Map& map, optional 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("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); diff --git a/benchmark/fixtures/api/cache.db b/benchmark/fixtures/api/cache.db index 5978c1659d..7043eb6fdb 100644 Binary files a/benchmark/fixtures/api/cache.db and b/benchmark/fixtures/api/cache.db differ -- cgit v1.2.1