Skip to content

Commit 67a4902

Browse files
committed
Don't try to compile benchmarks on unsupported platforms
WASM, iOS and Redox do not support `run_on_demand`, and compiling criterion on WASM can be troublesome.
1 parent 7df2c86 commit 67a4902

2 files changed

Lines changed: 70 additions & 56 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ redox_syscall = "0.7"
132132

133133
[dev-dependencies]
134134
colorous = "1.0.12"
135-
criterion = { version = "0.8.1", default-features = false, features = [
136-
"cargo_bench_support",
137-
] }
138135
web-time = "1.0.0"
139136
winit = "0.30.0"
140137

@@ -151,6 +148,9 @@ features = ["jpeg"]
151148
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
152149
# Turn rayon back on everywhere else; creating the separate entry resets the features to default.
153150
rayon = "1.5.1"
151+
criterion = { version = "0.8.1", default-features = false, features = [
152+
"cargo_bench_support",
153+
] }
154154

155155
[target.'cfg(target_family = "wasm")'.dev-dependencies]
156156
wasm-bindgen-test = "0.3"

benches/buffer_mut.rs

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,80 @@
11
#![allow(deprecated)] // TODO
22

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

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();
2520

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);
2823

29-
if let winit::event::Event::AboutToWait = ev {
30-
elwt.exit();
24+
if let winit::event::Event::AboutToWait = ev {
25+
elwt.exit();
3126

32-
let mut surface = Surface::new(&context, &window).unwrap();
27+
let mut surface = Surface::new(&context, &window).unwrap();
3328

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();
4136

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+
}
4842
});
43+
});
4944

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+
}
5852
});
59-
}
60-
})
61-
.unwrap();
62-
}
53+
});
54+
}
55+
})
56+
.unwrap();
6357
}
6458

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

Comments
 (0)