From feaf6985c11f6ac6ea9f42b07e8b9b17d88cb881 Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Sun, 9 Jan 2022 12:49:20 +0100 Subject: [PATCH] Fix benchmark --- benches/tesselation.rs | 25 ++++++++++++++++++++++--- src/io/mod.rs | 1 + src/io/static_tile_fetcher.rs | 4 ++++ src/io/web_tile_fetcher.rs | 5 +++++ src/lib.rs | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/benches/tesselation.rs b/benches/tesselation.rs index 19c46ae1..ac00f19c 100644 --- a/benches/tesselation.rs +++ b/benches/tesselation.rs @@ -1,6 +1,7 @@ use criterion::{criterion_group, criterion_main, Criterion}; use lyon::tessellation::VertexBuffers; -use mapr::io::static_database; +use mapr::io::static_tile_fetcher::StaticTileFetcher; +use mapr::io::{static_tile_fetcher, TileFetcher}; use mapr::tesselation::Tesselated; use std::io::Cursor; use vector_tile::parse_tile_reader; @@ -15,8 +16,17 @@ fn tessselate_fill(tile: &Tile) { } fn tile1(c: &mut Criterion) { + let fetcher = StaticTileFetcher::new(); let tile = parse_tile_reader(&mut Cursor::new( - static_database::get_tile(&(2179u32, 1421u32, 12u8).into()) + fetcher + .sync_fetch_tile( + &( + mapr::example::MUNICH_X, + mapr::example::MUNICH_Y, + mapr::example::MUNICH_Z, + ) + .into(), + ) .unwrap() .contents(), )) @@ -27,8 +37,17 @@ fn tile1(c: &mut Criterion) { } fn tile2(c: &mut Criterion) { + let fetcher = StaticTileFetcher::new(); let tile = parse_tile_reader(&mut Cursor::new( - static_database::get_tile(&(2179u32, 1421u32, 12u8).into()) + fetcher + .sync_fetch_tile( + &( + mapr::example::MUNICH_X, + mapr::example::MUNICH_Y, + mapr::example::MUNICH_Z, + ) + .into(), + ) .unwrap() .contents(), )) diff --git a/src/io/mod.rs b/src/io/mod.rs index 6326c4a7..d4753861 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -18,4 +18,5 @@ pub trait TileFetcher { fn new() -> Self; async fn fetch_tile(&self, coords: &TileCoords) -> Result, Error>; + fn sync_fetch_tile(&self, coords: &TileCoords) -> Result, Error>; } diff --git a/src/io/static_tile_fetcher.rs b/src/io/static_tile_fetcher.rs index 29d3d460..5193a1a0 100644 --- a/src/io/static_tile_fetcher.rs +++ b/src/io/static_tile_fetcher.rs @@ -26,6 +26,10 @@ impl TileFetcher for StaticTileFetcher { } async fn fetch_tile(&self, coords: &TileCoords) -> Result, Error> { + self.sync_fetch_tile(coords) + } + + fn sync_fetch_tile(&self, coords: &TileCoords) -> Result, Error> { let tile = TILES .get_file(format!("{}/{}/{}.{}", coords.z, coords.x, coords.y, "pbf")) .ok_or_else(|| Error::File("Failed to load tile from within the binary".to_string()))?; diff --git a/src/io/web_tile_fetcher.rs b/src/io/web_tile_fetcher.rs index ef7b9fb4..35ddb105 100644 --- a/src/io/web_tile_fetcher.rs +++ b/src/io/web_tile_fetcher.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::io::{HttpFetcher, TileFetcher}; use crate::platform::PlatformHttpFetcher; use async_trait::async_trait; +use core::panicking::panic; pub struct WebTileFetcher { http_fetcher: PlatformHttpFetcher, @@ -29,6 +30,10 @@ impl TileFetcher for WebTileFetcher { ) .await } + + fn sync_fetch_tile(&self, _coords: &TileCoords) -> Result, Error> { + panic!("Unable to fetch sync from the web!"); + } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index d2cb481a..2c7e7a30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ mod platform; pub(crate) mod coords; pub(crate) mod error; -pub(crate) mod example; pub(crate) mod render; pub(crate) mod util; @@ -13,4 +12,5 @@ pub mod io; pub mod main_loop; // Used for benchmarking +pub mod example; pub mod tesselation;