[librsvg: 1/9] Add a benchmark for pixbuf_from_surface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/9] Add a benchmark for pixbuf_from_surface
- Date: Fri, 29 May 2020 21:15:52 +0000 (UTC)
commit 8658831fb7a900620accc505f38090616e9a886d
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 507bb6ed..3cbba348 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -695,6 +695,7 @@ dependencies = [
"cairo-rs 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cairo-sys-rs 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "criterion 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf-sys 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
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 a8029640..742bf2a0 100644
--- a/librsvg/lib.rs
+++ b/librsvg/lib.rs
@@ -53,4 +53,4 @@ mod messages;
mod c_api;
mod color_utils;
mod dpi;
-mod pixbuf_utils;
+pub mod pixbuf_utils;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]