Move benchmarks into separate crate ♾

So that CI does not have to build criterion each time.
This commit is contained in:
Laurenz 2020-11-25 19:28:04 +01:00
parent e30d896c7b
commit b4f809f1ea
4 changed files with 36 additions and 20 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
/target /target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
bench/target
tests/png tests/png
tests/pdf tests/pdf
_things _things

View File

@ -4,6 +4,9 @@ version = "0.1.0"
authors = ["The Typst Project Developers"] authors = ["The Typst Project Developers"]
edition = "2018" edition = "2018"
[workspace]
members = ["bench"]
[features] [features]
default = ["fs", "anyhow"] default = ["fs", "anyhow"]
fs = ["fontdock/fs"] fs = ["fontdock/fs"]
@ -23,7 +26,6 @@ serde = { version = "1", features = ["derive"], optional = true }
anyhow = { version = "1", optional = true } anyhow = { version = "1", optional = true }
[dev-dependencies] [dev-dependencies]
criterion = "0.3"
memmap = "0.7" memmap = "0.7"
tiny-skia = "0.2" tiny-skia = "0.2"
@ -33,9 +35,6 @@ opt-level = 2
[profile.release] [profile.release]
lto = true lto = true
[lib]
bench = false
[[bin]] [[bin]]
name = "typst" name = "typst"
required-features = ["fs", "anyhow"] required-features = ["fs", "anyhow"]
@ -44,8 +43,3 @@ required-features = ["fs", "anyhow"]
name = "typeset" name = "typeset"
required-features = ["fs"] required-features = ["fs"]
harness = false harness = false
[[bench]]
name = "benchmarks"
required-features = ["fs"]
harness = false

16
bench/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "typst-bench"
version = "0.0.1"
authors = ["The Typst Project Developers"]
edition = "2018"
publish = false
[dependencies]
fontdock = { path = "../../fontdock" }
typst = { path = ".." }
criterion = "0.3"
[[bench]]
name = "typst"
path = "src/bench.rs"
harness = false

View File

@ -5,16 +5,21 @@ use criterion::{criterion_group, criterion_main, Criterion};
use fontdock::fs::{FsIndex, FsSource}; use fontdock::fs::{FsIndex, FsSource};
use typst::eval::{eval, State}; use typst::eval::{eval, State};
use typst::export::pdf;
use typst::font::FontLoader; use typst::font::FontLoader;
use typst::layout::layout; use typst::layout::layout;
use typst::parse::parse; use typst::parse::parse;
use typst::typeset; use typst::typeset;
const FONT_DIR: &str = "fonts"; const FONT_DIR: &str = "fonts";
const COMA: &str = include_str!("../tests/typ/coma.typ"); const COMA: &str = include_str!("../../tests/typ/coma.typ");
fn benchmarks(c: &mut Criterion) { fn benchmarks(c: &mut Criterion) {
let state = State::default(); macro_rules! bench {
($name:literal: $($tts:tt)*) => {
c.bench_function($name, |b| b.iter(|| $($tts)*));
};
}
let mut index = FsIndex::new(); let mut index = FsIndex::new();
index.search_dir(FONT_DIR); index.search_dir(FONT_DIR);
@ -25,18 +30,18 @@ fn benchmarks(c: &mut Criterion) {
descriptors, descriptors,
))); )));
// Prepare intermediate results and run warm.
let state = State::default();
let tree = parse(COMA).output; let tree = parse(COMA).output;
let document = eval(&tree, state.clone()).output; let document = eval(&tree, state.clone()).output;
let _ = layout(&document, Rc::clone(&loader)); let layouts = layout(&document, Rc::clone(&loader));
c.bench_function("parse-coma", |b| b.iter(|| parse(COMA))); // Bench!
c.bench_function("eval-coma", |b| b.iter(|| eval(&tree, state.clone()))); bench!("parse-coma": parse(COMA));
c.bench_function("layout-coma", |b| { bench!("eval-coma": eval(&tree, state.clone()));
b.iter(|| layout(&document, Rc::clone(&loader))) bench!("layout-coma": layout(&document, Rc::clone(&loader)));
}); bench!("typeset-coma": typeset(COMA, state.clone(), Rc::clone(&loader)));
c.bench_function("typeset-coma", |b| { bench!("export-pdf-coma": pdf::export(&layouts, &loader.borrow()));
b.iter(|| typeset(COMA, state.clone(), Rc::clone(&loader)))
});
} }
criterion_group!(benches, benchmarks); criterion_group!(benches, benchmarks);