|
1 | 1 | #![allow(deprecated)] // TODO |
2 | 2 |
|
3 | | -use criterion::{criterion_group, criterion_main, Criterion}; |
| 3 | +#[cfg(not(any( |
| 4 | + target_family = "wasm", |
| 5 | + all(target_vendor = "apple", not(target_os = "macos")), |
| 6 | + target_os = "redox" |
| 7 | +)))] |
| 8 | +fn buffer_mut(c: &mut criterion::Criterion) { |
| 9 | + use criterion::black_box; |
| 10 | + use softbuffer::{Context, Surface}; |
| 11 | + use std::num::NonZeroU32; |
| 12 | + use winit::event_loop::ControlFlow; |
| 13 | + use winit::platform::run_on_demand::EventLoopExtRunOnDemand; |
4 | 14 |
|
5 | | -fn buffer_mut(c: &mut Criterion) { |
6 | | - #[cfg(target_family = "wasm")] |
7 | | - { |
8 | | - // Do nothing. |
9 | | - let _ = c; |
10 | | - } |
11 | | - |
12 | | - #[cfg(not(target_family = "wasm"))] |
13 | | - { |
14 | | - use criterion::black_box; |
15 | | - use softbuffer::{Context, Surface}; |
16 | | - use std::num::NonZeroU32; |
17 | | - use winit::event_loop::ControlFlow; |
18 | | - use winit::platform::run_on_demand::EventLoopExtRunOnDemand; |
19 | | - |
20 | | - let mut evl = winit::event_loop::EventLoop::new().unwrap(); |
21 | | - let context = Context::new(evl.owned_display_handle()).unwrap(); |
22 | | - let window = evl |
23 | | - .create_window(winit::window::Window::default_attributes().with_visible(false)) |
24 | | - .unwrap(); |
| 15 | + let mut evl = winit::event_loop::EventLoop::new().unwrap(); |
| 16 | + let context = Context::new(evl.owned_display_handle()).unwrap(); |
| 17 | + let window = evl |
| 18 | + .create_window(winit::window::Window::default_attributes().with_visible(false)) |
| 19 | + .unwrap(); |
25 | 20 |
|
26 | | - evl.run_on_demand(move |ev, elwt| { |
27 | | - elwt.set_control_flow(ControlFlow::Poll); |
| 21 | + evl.run_on_demand(move |ev, elwt| { |
| 22 | + elwt.set_control_flow(ControlFlow::Poll); |
28 | 23 |
|
29 | | - if let winit::event::Event::AboutToWait = ev { |
30 | | - elwt.exit(); |
| 24 | + if let winit::event::Event::AboutToWait = ev { |
| 25 | + elwt.exit(); |
31 | 26 |
|
32 | | - let mut surface = Surface::new(&context, &window).unwrap(); |
| 27 | + let mut surface = Surface::new(&context, &window).unwrap(); |
33 | 28 |
|
34 | | - let size = window.inner_size(); |
35 | | - surface |
36 | | - .resize( |
37 | | - NonZeroU32::new(size.width).unwrap(), |
38 | | - NonZeroU32::new(size.height).unwrap(), |
39 | | - ) |
40 | | - .unwrap(); |
| 29 | + let size = window.inner_size(); |
| 30 | + surface |
| 31 | + .resize( |
| 32 | + NonZeroU32::new(size.width).unwrap(), |
| 33 | + NonZeroU32::new(size.height).unwrap(), |
| 34 | + ) |
| 35 | + .unwrap(); |
41 | 36 |
|
42 | | - c.bench_function("buffer_mut()", |b| { |
43 | | - b.iter(|| { |
44 | | - for _ in 0..500 { |
45 | | - black_box(surface.buffer_mut().unwrap()); |
46 | | - } |
47 | | - }); |
| 37 | + c.bench_function("buffer_mut()", |b| { |
| 38 | + b.iter(|| { |
| 39 | + for _ in 0..500 { |
| 40 | + black_box(surface.buffer_mut().unwrap()); |
| 41 | + } |
48 | 42 | }); |
| 43 | + }); |
49 | 44 |
|
50 | | - c.bench_function("pixels_mut()", |b| { |
51 | | - let mut buffer = surface.buffer_mut().unwrap(); |
52 | | - b.iter(|| { |
53 | | - for _ in 0..500 { |
54 | | - let x: &mut [u32] = &mut buffer; |
55 | | - black_box(x); |
56 | | - } |
57 | | - }); |
| 45 | + c.bench_function("pixels_mut()", |b| { |
| 46 | + let mut buffer = surface.buffer_mut().unwrap(); |
| 47 | + b.iter(|| { |
| 48 | + for _ in 0..500 { |
| 49 | + let x: &mut [u32] = &mut buffer; |
| 50 | + black_box(x); |
| 51 | + } |
58 | 52 | }); |
59 | | - } |
60 | | - }) |
61 | | - .unwrap(); |
62 | | - } |
| 53 | + }); |
| 54 | + } |
| 55 | + }) |
| 56 | + .unwrap(); |
63 | 57 | } |
64 | 58 |
|
65 | | -criterion_group!(benches, buffer_mut); |
66 | | -criterion_main!(benches); |
| 59 | +#[cfg(not(any( |
| 60 | + target_family = "wasm", |
| 61 | + all(target_vendor = "apple", not(target_os = "macos")), |
| 62 | + target_os = "redox" |
| 63 | +)))] |
| 64 | +criterion::criterion_group!(benches, buffer_mut); |
| 65 | + |
| 66 | +#[cfg(not(any( |
| 67 | + target_family = "wasm", |
| 68 | + all(target_vendor = "apple", not(target_os = "macos")), |
| 69 | + target_os = "redox" |
| 70 | +)))] |
| 71 | +criterion::criterion_main!(benches); |
| 72 | + |
| 73 | +#[cfg(any( |
| 74 | + target_family = "wasm", |
| 75 | + all(target_vendor = "apple", not(target_os = "macos")), |
| 76 | + target_os = "redox" |
| 77 | +))] |
| 78 | +fn main() { |
| 79 | + panic!("unsupported on WASM, iOS and Redox"); |
| 80 | +} |
0 commit comments