forked from rust-windowing/softbuffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_mut.rs
More file actions
68 lines (57 loc) · 2.14 KB
/
buffer_mut.rs
File metadata and controls
68 lines (57 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#![allow(deprecated)] // TODO
use criterion::{criterion_group, criterion_main, Criterion};
fn buffer_mut(c: &mut Criterion) {
#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
{
// Do nothing.
let _ = c;
}
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
{
use criterion::black_box;
use softbuffer::{Context, Surface};
use std::num::NonZeroU32;
use winit::event_loop::ControlFlow;
use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
let mut evl = winit::event_loop::EventLoop::new().unwrap();
let window = evl
.create_window(winit::window::Window::default_attributes().with_visible(false))
.unwrap();
evl.run_on_demand(move |ev, elwt| {
elwt.set_control_flow(ControlFlow::Poll);
if let winit::event::Event::AboutToWait = ev {
elwt.exit();
let mut surface = {
let context = Context::new(elwt).unwrap();
Surface::new(&context, &window).unwrap()
};
let size = window.inner_size();
surface
.resize(
NonZeroU32::new(size.width).unwrap(),
NonZeroU32::new(size.height).unwrap(),
)
.unwrap();
c.bench_function("buffer_mut()", |b| {
b.iter(|| {
for _ in 0..500 {
black_box(surface.buffer_mut().unwrap());
}
});
});
c.bench_function("pixels_mut()", |b| {
let mut buffer = surface.buffer_mut().unwrap();
b.iter(|| {
for _ in 0..500 {
let x: &mut [u32] = &mut buffer.pixels_platform_dependent_mut();
black_box(x);
}
});
});
}
})
.unwrap();
}
}
criterion_group!(benches, buffer_mut);
criterion_main!(benches);