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
|
use criterion::{criterion_group, criterion_main, Criterion};
use rsvg::{
surface_utils::{
shared_surface::{ExclusiveImageSurface, SurfaceType},
ImageSurfaceDataExt, Pixel,
},
IRect,
};
const BOUNDS: IRect = IRect {
x0: 0,
y0: 0,
x1: 256,
y1: 256,
};
fn bench_pixbuf_from_surface(c: &mut Criterion) {
c.bench_function("pixbuf_from_surface", |b| {
let mut surface = ExclusiveImageSurface::new(256, 256, SurfaceType::SRgb).unwrap();
// Fill the surface with interesting data
surface.modify(&mut |data, stride| {
for y in BOUNDS.y_range() {
for x in BOUNDS.x_range() {
let pixel = Pixel {
r: x as u8,
g: y as u8,
b: x.max(y) as u8,
a: 255,
};
data.set_pixel(stride, pixel, x as u32, y as u32);
}
}
});
let surface = surface.share().unwrap();
b.iter(|| surface.to_pixbuf().unwrap())
});
}
criterion_group!(benches, bench_pixbuf_from_surface);
criterion_main!(benches);
|