[librsvg/librsvg-2.48] Add a benchmark for pixbuf_from_surface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.48] Add a benchmark for pixbuf_from_surface
- Date: Fri, 29 May 2020 20:48:06 +0000 (UTC)
commit 94e984301137a874b0657648f051f93cd7859f3e
Author: Federico Mena Quintero <federico gnome org>
Date: Thu May 28 14:02:21 2020 -0500
Add a benchmark for pixbuf_from_surface
Cargo.lock | 1 +
librsvg/Cargo.toml | 9 +++++-
librsvg/benches/pixbuf_from_surface.rs | 54 ++++++++++++++++++++++++++++++++++
librsvg/lib.rs | 2 +-
4 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 8cab1f1e..3b513d80 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -686,6 +686,7 @@ dependencies = [
"cairo-rs",
"cairo-sys-rs",
"cast",
+ "criterion",
"gdk-pixbuf",
"gdk-pixbuf-sys",
"gio",
diff --git a/librsvg/Cargo.toml b/librsvg/Cargo.toml
index 42a0936d..669ec866 100644
--- a/librsvg/Cargo.toml
+++ b/librsvg/Cargo.toml
@@ -8,7 +8,7 @@ edition = "2018"
[lib]
name = "rsvg_c_api"
path = "lib.rs"
-crate-type = [ "staticlib" ]
+crate-type = [ "staticlib", "rlib" ]
[dependencies]
bitflags = "1.0"
@@ -25,3 +25,10 @@ gobject-sys = "0.9.0"
libc = "0.2"
rsvg_internals = { path = "../rsvg_internals" }
url = "2"
+
+[dev-dependencies]
+criterion = "0.3"
+
+[[bench]]
+name = "pixbuf_from_surface"
+harness = false
diff --git a/librsvg/benches/pixbuf_from_surface.rs b/librsvg/benches/pixbuf_from_surface.rs
new file mode 100644
index 00000000..7e2cf26a
--- /dev/null
+++ b/librsvg/benches/pixbuf_from_surface.rs
@@ -0,0 +1,54 @@
+use std::time::Duration;
+
+use criterion::{criterion_group, criterion_main, Criterion};
+
+use rsvg_c_api::pixbuf_utils::pixbuf_from_surface;
+use rsvg_internals::rect::IRect;
+use rsvg_internals::surface_utils::{
+ shared_surface::{ExclusiveImageSurface, SurfaceType},
+ ImageSurfaceDataExt, Pixel,
+};
+
+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(|| {
+ let _pixbuf = pixbuf_from_surface(&surface).unwrap();
+ })
+ });
+}
+
+
+criterion_group!(
+ name = benches;
+ config = Criterion::default().measurement_time(Duration::from_secs(10));
+ targets = bench_pixbuf_from_surface,
+);
+criterion_main!(benches);
diff --git a/librsvg/lib.rs b/librsvg/lib.rs
index bec12ede..29fca04e 100644
--- a/librsvg/lib.rs
+++ b/librsvg/lib.rs
@@ -50,4 +50,4 @@ mod messages;
mod c_api;
mod color_utils;
-mod pixbuf_utils;
+pub mod pixbuf_utils;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]