Fix benchmark

This commit is contained in:
Maximilian Ammann 2022-01-09 12:49:20 +01:00
parent fa3537dad8
commit feaf6985c1
5 changed files with 33 additions and 4 deletions

View File

@ -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(),
))

View File

@ -18,4 +18,5 @@ pub trait TileFetcher {
fn new() -> Self;
async fn fetch_tile(&self, coords: &TileCoords) -> Result<Vec<u8>, Error>;
fn sync_fetch_tile(&self, coords: &TileCoords) -> Result<Vec<u8>, Error>;
}

View File

@ -26,6 +26,10 @@ impl TileFetcher for StaticTileFetcher {
}
async fn fetch_tile(&self, coords: &TileCoords) -> Result<Vec<u8>, Error> {
self.sync_fetch_tile(coords)
}
fn sync_fetch_tile(&self, coords: &TileCoords) -> Result<Vec<u8>, 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()))?;

View File

@ -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<Vec<u8>, Error> {
panic!("Unable to fetch sync from the web!");
}
}
#[cfg(test)]

View File

@ -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;