-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathbuffer_mut.rs
More file actions
97 lines (84 loc) · 3.03 KB
/
buffer_mut.rs
File metadata and controls
97 lines (84 loc) · 3.03 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![allow(deprecated)] // TODO
#[cfg(not(any(
target_family = "wasm",
all(target_vendor = "apple", not(target_os = "macos")),
target_os = "redox"
)))]
fn buffer_mut(c: &mut criterion::Criterion) {
use criterion::black_box;
use softbuffer::{Context, Pixel, 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 context = Context::new(evl.owned_display_handle()).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 = 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(|| {
black_box(surface.buffer_mut().unwrap());
});
});
c.bench_function("pixels()", |b| {
let mut buffer = surface.buffer_mut().unwrap();
b.iter(|| {
let pixels: &mut [Pixel] = buffer.pixels();
black_box(pixels);
});
});
c.bench_function("fill pixels", |b| {
let mut buffer = surface.buffer_mut().unwrap();
b.iter(|| {
let buffer = black_box(&mut buffer);
buffer.pixels().fill(Pixel::default());
});
});
c.bench_function("render pixels_iter", |b| {
let mut buffer = surface.buffer_mut().unwrap();
b.iter(|| {
let buffer = black_box(&mut buffer);
for (x, y, pixel) in buffer.pixels_iter() {
let red = (x & 0xff) ^ (y & 0xff);
let green = (x & 0x7f) ^ (y & 0x7f);
let blue = (x & 0x3f) ^ (y & 0x3f);
*pixel = Pixel::new_rgb(red as u8, green as u8, blue as u8);
}
});
});
}
})
.unwrap();
}
#[cfg(not(any(
target_family = "wasm",
all(target_vendor = "apple", not(target_os = "macos")),
target_os = "redox"
)))]
criterion::criterion_group!(benches, buffer_mut);
#[cfg(not(any(
target_family = "wasm",
all(target_vendor = "apple", not(target_os = "macos")),
target_os = "redox"
)))]
criterion::criterion_main!(benches);
#[cfg(any(
target_family = "wasm",
all(target_vendor = "apple", not(target_os = "macos")),
target_os = "redox"
))]
fn main() {
panic!("unsupported on WASM, iOS and Redox");
}