mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Add a render benchmark
This commit is contained in:
parent
01a97a5ed1
commit
9f7ec58cbc
@ -26,6 +26,9 @@ codegen-units = 1
|
||||
opt-level = 's'
|
||||
panic = "abort"
|
||||
|
||||
[profile.bench]
|
||||
debug = true
|
||||
|
||||
[features]
|
||||
web-webgl = ["wgpu/webgl"]
|
||||
|
||||
@ -111,6 +114,10 @@ crate-type = ["bin"]
|
||||
name = "tessellation"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "render"
|
||||
harness = false
|
||||
|
||||
[package.metadata.android]
|
||||
apk_name = "mapr-demo"
|
||||
[[package.metadata.android.uses_permission]]
|
||||
|
||||
20
benches/render.rs
Normal file
20
benches/render.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use mapr::{MapBuilder, ScheduleMethod, TokioScheduleMethod};
|
||||
|
||||
fn render(c: &mut Criterion) {
|
||||
c.bench_function("render", |b| {
|
||||
b.iter(|| {
|
||||
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
||||
|
||||
MapBuilder::from_window("A fantastic window!")
|
||||
.with_schedule_method(ScheduleMethod::Tokio(TokioScheduleMethod::new(Some(
|
||||
"/tmp/mapr_cache".to_string(),
|
||||
))))
|
||||
.build()
|
||||
.run_sync_with_max_frames(Some(1000));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, render);
|
||||
criterion_main!(benches);
|
||||
@ -35,12 +35,18 @@ impl Map {
|
||||
self.event_loop,
|
||||
self.scheduler,
|
||||
Box::new(self.style),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn run_sync(self) {
|
||||
self.run_sync_with_max_frames(None);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn run_sync_with_max_frames(self, max_frames: Option<u64>) {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
@ -51,6 +57,7 @@ impl Map {
|
||||
self.event_loop,
|
||||
self.scheduler,
|
||||
Box::new(self.style),
|
||||
max_frames,
|
||||
)
|
||||
.await;
|
||||
})
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
//! * Platform Events like suspend/resume
|
||||
//! * Render a new frame
|
||||
|
||||
use log::{error, trace};
|
||||
use log::{error, info, trace};
|
||||
use style_spec::Style;
|
||||
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
@ -19,6 +19,7 @@ pub async fn run(
|
||||
event_loop: EventLoop<()>,
|
||||
mut scheduler: Box<IOScheduler>,
|
||||
style: Box<Style>,
|
||||
max_frames: Option<u64>,
|
||||
) {
|
||||
let mut input = InputController::new(0.2, 100.0, 0.1);
|
||||
let mut maybe_state: Option<RenderState> = {
|
||||
@ -34,6 +35,8 @@ pub async fn run(
|
||||
|
||||
let mut last_render_time = Instant::now();
|
||||
|
||||
let mut current_frame: u64 = 0;
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
/* FIXME: On Android we need to initialize the surface on Event::Resumed. On desktop this
|
||||
event is not fired and we can do surface initialization anytime. Clean this up.
|
||||
@ -108,6 +111,15 @@ pub async fn run(
|
||||
},
|
||||
// All other errors (Outdated, Timeout) should be resolved by the next frame
|
||||
Err(e) => eprintln!("{:?}", e),
|
||||
};
|
||||
|
||||
current_frame += 1;
|
||||
|
||||
if let Some(max_frames) = max_frames {
|
||||
if current_frame >= max_frames {
|
||||
info!("Exiting because maximum frames reached.");
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Suspended => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user