Commit d3f1c751 authored by Alex Butler's avatar Alex Butler

Add layout benchmark & reference test

parent 964795bd
...@@ -66,8 +66,7 @@ test:benches: ...@@ -66,8 +66,7 @@ test:benches:
dependencies: dependencies:
- build:nightly - build:nightly
script: script:
- cargo +nightly test --bench cache --all-features - cargo +nightly test --benches --all-features
- cargo +nightly test --bench draw --all-features
build:nightly:gpu_cache: build:nightly:gpu_cache:
stage: build stage: build
extern crate test;
use blake2::{Blake2s, Digest};
use rusttype::*;
use std::io::Write;
fn layout_a_sentence(b: &mut test::Bencher) {
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 \
clause and sometimes one or more subordinate clauses.";
let font =
Font::from_bytes(include_bytes!("../fonts/opensans/OpenSans-Italic.ttf") as &[u8]).unwrap();
let mut glyphs = vec![];
b.iter(|| {
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 {
id =,
scale_x = g.scale().x,
scale_y = g.scale().y,
pos_x = g.position().x,
pos_y = g.position().y,
format!("{:x}", hash.result()),
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