diff options
Diffstat (limited to 'benchmark/api/render.benchmark.cpp')
-rw-r--r-- | benchmark/api/render.benchmark.cpp | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp index 9a91e8b3bc..3cff0d9056 100644 --- a/benchmark/api/render.benchmark.cpp +++ b/benchmark/api/render.benchmark.cpp @@ -8,7 +8,7 @@ #include <mbgl/renderer/renderer.hpp> #include <mbgl/style/style.hpp> #include <mbgl/style/image.hpp> -#include <mbgl/storage/default_file_source.hpp> +#include <mbgl/storage/resource_options.hpp> #include <mbgl/storage/network_status.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/io.hpp> @@ -18,32 +18,36 @@ using namespace mbgl; namespace { +static std::string cachePath { "benchmark/fixtures/api/cache.db" }; +constexpr double pixelRatio { 1.0 }; +constexpr Size size { 1000, 1000 }; + class RenderBenchmark { public: RenderBenchmark() { NetworkStatus::Set(NetworkStatus::Status::Offline); - fileSource.setAccessToken("foobar"); } util::RunLoop loop; - DefaultFileSource fileSource { "benchmark/fixtures/api/cache.db", "." }; ThreadPool threadPool { 4 }; }; - + static void prepare(Map& map, optional<std::string> json = {}) { 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 - map.getStyle().addImage(std::make_unique<style::Image>("test-icon", - decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0)); + + 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) { RenderBenchmark bench; - HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, - bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) }; + HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; + Map map { frontend, MapObserver::nullObserver(), bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map); while (state.KeepRunning()) { @@ -53,9 +57,10 @@ static void API_renderStill_reuse_map(::benchmark::State& state) { static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state) { RenderBenchmark bench; - HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, - bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) }; + HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; + Map map { frontend, MapObserver::nullObserver(), bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json")); while (state.KeepRunning()) { @@ -65,10 +70,11 @@ static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) { RenderBenchmark bench; - HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, - bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) }; - + HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; + Map map { frontend, MapObserver::nullObserver(), bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; + while (state.KeepRunning()) { prepare(map, { "{}" }); frontend.render(map); @@ -79,11 +85,12 @@ 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()) { - HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.threadPool }; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, - bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) }; + HeadlessFrontend frontend { size, pixelRatio, bench.threadPool }; + Map map { frontend, MapObserver::nullObserver(), bench.threadPool, + MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio), + ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") }; prepare(map); frontend.render(map); } |