Commit bb9d9d2f authored by Alex Butler's avatar Alex Butler

Use criterion for stable benchmarks

parent 6b282b02
Pipeline #6960 passed with stages
in 5 minutes and 15 seconds
......@@ -43,23 +43,23 @@ test:stable:gpu_cache:
script:
- cargo +stable test --features 'gpu_cache'
build:nightly:gpu_cache:
stage: build
variables:
toolchain: nightly
script:
- cargo +nightly build --features 'gpu_cache'
# Heavier testing using rusttype-dev
test:dev:
stage: test
variables:
toolchain: nightly
toolchain: stable
dependencies:
- build:nightly:gpu_cache
- build:stable:gpu_cache
script:
- cargo test --workspace --all-features
- cargo test --workspace --all-features --benches
build:nightly:gpu_cache:
stage: build
variables:
toolchain: nightly
script:
- cargo +nightly test --all --all-features
- cargo +nightly test --all --all-features --benches
- cargo +nightly build --features 'gpu_cache'
build:redox:
stage: build
......
......@@ -5,10 +5,23 @@ description = "Tests, examples & benchmarks avoiding dependency feature bleed"
edition = "2018"
publish = false
[dependencies]
[dev-dependencies]
rusttype = { path = "../", features = ["gpu_cache"] }
glium = "0.25"
image = { version = "0.23", default-features = false, features = ["png"] }
arrayvec = { version = "0.5", default-features = false }
once_cell = "1"
blake2 = "0.8"
criterion = "0.3"
[[bench]]
name = "cache"
harness = false
[[bench]]
name = "draw"
harness = false
[[bench]]
name = "layout"
harness = false
This diff is collapsed.
#![feature(test)]
extern crate test;
use once_cell::sync::Lazy;
use blake2::{Blake2s, Digest};
use criterion::{criterion_group, criterion_main, Criterion};
use once_cell::sync::Lazy;
use rusttype::*;
static DEJA_VU_MONO: Lazy<Font<'static>> = Lazy::new(|| {
......@@ -12,8 +10,7 @@ static OPEN_SANS_ITALIC: Lazy<Font<'static>> = Lazy::new(|| {
Font::from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8]).unwrap()
});
#[bench]
fn draw_big_biohazard(b: &mut test::Bencher) {
fn bench_draw_big_biohazard(c: &mut Criterion) {
let glyph = DEJA_VU_MONO
.glyph('☣')
.scaled(Scale::uniform(600.0))
......@@ -29,22 +26,22 @@ fn draw_big_biohazard(b: &mut test::Bencher) {
);
let mut target = [0u8; WIDTH * HEIGHT];
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
c.bench_function("draw_big_biohazard", |b| {
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"8e3927a33c6d563d45f82fb9620dea8036274b403523a2e98cd5f93eafdb2125"
);
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"8e3927a33c6d563d45f82fb9620dea8036274b403523a2e98cd5f93eafdb2125"
);
}
#[bench]
fn draw_w(b: &mut test::Bencher) {
fn bench_draw_w(c: &mut Criterion) {
let glyph = DEJA_VU_MONO
.glyph('w')
.scaled(Scale::uniform(16.0))
......@@ -60,22 +57,23 @@ fn draw_w(b: &mut test::Bencher) {
);
let mut target = [0u8; WIDTH * HEIGHT];
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
c.bench_function("draw_w", |b| {
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"c0e795601e3412144d1bfdc0cd94d9507aa9775a0f0f4f9862fe7ec7e83d7684"
);
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"c0e795601e3412144d1bfdc0cd94d9507aa9775a0f0f4f9862fe7ec7e83d7684"
);
}
#[bench]
fn draw_iota(b: &mut test::Bencher) {
fn bench_draw_iota(c: &mut Criterion) {
let glyph = OPEN_SANS_ITALIC
.glyph('ΐ')
.scaled(Scale::uniform(60.0))
......@@ -91,16 +89,27 @@ fn draw_iota(b: &mut test::Bencher) {
);
let mut target = [0u8; WIDTH * HEIGHT];
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
c.bench_function("draw_iota", |b| {
b.iter(|| {
glyph.draw(|x, y, alpha| {
let (x, y) = (x as usize, y as usize);
target[WIDTH * y + x] = (alpha * 255.0) as u8;
})
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"cdad348e38263a13f68ae41a95ce3b900d2881375a745232309ebd568a27cd4c"
);
});
// verify the draw result against static reference hash
assert_eq!(
format!("{:x}", Blake2s::digest(&target)),
"cdad348e38263a13f68ae41a95ce3b900d2881375a745232309ebd568a27cd4c"
);
}
criterion_group!(
benches,
bench_draw_big_biohazard,
bench_draw_w,
bench_draw_iota,
);
criterion_main!(benches);
#![feature(test)]
extern crate test;
use blake2::{Blake2s, Digest};
use criterion::{criterion_group, criterion_main, Criterion};
use rusttype::*;
use std::io::Write;
#[bench]
fn layout_a_sentence(b: &mut test::Bencher) {
fn bench_layout_a_sentence(c: &mut Criterion) {
const SENTENCE: &str =
"a set of words that is complete in itself, typically containing a subject and predicate, \
conveying a statement, question, exclamation, or command, and consisting of a main \
......@@ -15,28 +12,35 @@ fn layout_a_sentence(b: &mut test::Bencher) {
let font =
Font::from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8]).unwrap();
let mut glyphs = vec![];
b.iter(|| {
glyphs.clear();
glyphs.extend(font.layout(SENTENCE, Scale::uniform(25.0), point(100.0, 25.0)))
});
c.bench_function("layout_a_sentence", |b| {
let mut glyphs = vec![];
b.iter(|| {
glyphs.clear();
glyphs.extend(font.layout(SENTENCE, Scale::uniform(25.0), point(100.0, 25.0)))
});
// verify the layout result against static reference hash
let mut hash = Blake2s::default();
for g in glyphs {
write!(
hash,
"{id}:{scale_x}:{scale_y}:{pos_x}:{pos_y}",
id = g.id().0,
scale_x = g.scale().x,
scale_y = g.scale().y,
pos_x = g.position().x,
pos_y = g.position().y,
)
.unwrap();
}
assert_eq!(
format!("{:x}", hash.result()),
"c2a3483ddf5598ec869440c62d17efa5a4fe72f9893bcc05dd17be2adcaa7629"
);
// verify the layout result against static reference hash
let mut hash = Blake2s::default();
for g in glyphs {
write!(
hash,
"{id}:{scale_x}:{scale_y}:{pos_x}:{pos_y}",
id = g.id().0,
scale_x = g.scale().x,
scale_y = g.scale().y,
pos_x = g.position().x,
pos_y = g.position().y,
)
.unwrap();
}
assert_eq!(
format!("{:x}", hash.result()),
"c2a3483ddf5598ec869440c62d17efa5a4fe72f9893bcc05dd17be2adcaa7629"
);
});
}
criterion_group!(benches, bench_layout_a_sentence);
criterion_main!(benches);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment