diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-11-25 19:28:04 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-11-25 19:28:04 +0100 |
| commit | b4f809f1ea8a469d0bdee225f47d7f09bc22aa61 (patch) | |
| tree | 93a186e98a278588b42d61fdbe814151f3e6fce7 /bench | |
| parent | e30d896c7b871b1588925cadd10808c65e93d511 (diff) | |
Move benchmarks into separate crate ♾
So that CI does not have to build criterion each time.
Diffstat (limited to 'bench')
| -rw-r--r-- | bench/Cargo.toml | 16 | ||||
| -rw-r--r-- | bench/src/bench.rs | 48 |
2 files changed, 64 insertions, 0 deletions
diff --git a/bench/Cargo.toml b/bench/Cargo.toml new file mode 100644 index 00000000..25a112a1 --- /dev/null +++ b/bench/Cargo.toml @@ -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 diff --git a/bench/src/bench.rs b/bench/src/bench.rs new file mode 100644 index 00000000..e004c5ce --- /dev/null +++ b/bench/src/bench.rs @@ -0,0 +1,48 @@ +use std::cell::RefCell; +use std::rc::Rc; + +use criterion::{criterion_group, criterion_main, Criterion}; +use fontdock::fs::{FsIndex, FsSource}; + +use typst::eval::{eval, State}; +use typst::export::pdf; +use typst::font::FontLoader; +use typst::layout::layout; +use typst::parse::parse; +use typst::typeset; + +const FONT_DIR: &str = "fonts"; +const COMA: &str = include_str!("../../tests/typ/coma.typ"); + +fn benchmarks(c: &mut Criterion) { + macro_rules! bench { + ($name:literal: $($tts:tt)*) => { + c.bench_function($name, |b| b.iter(|| $($tts)*)); + }; + } + + let mut index = FsIndex::new(); + index.search_dir(FONT_DIR); + + let (files, descriptors) = index.into_vecs(); + let loader = Rc::new(RefCell::new(FontLoader::new( + Box::new(FsSource::new(files)), + descriptors, + ))); + + // Prepare intermediate results and run warm. + let state = State::default(); + let tree = parse(COMA).output; + let document = eval(&tree, state.clone()).output; + let layouts = layout(&document, Rc::clone(&loader)); + + // Bench! + bench!("parse-coma": parse(COMA)); + bench!("eval-coma": eval(&tree, state.clone())); + bench!("layout-coma": layout(&document, Rc::clone(&loader))); + bench!("typeset-coma": typeset(COMA, state.clone(), Rc::clone(&loader))); + bench!("export-pdf-coma": pdf::export(&layouts, &loader.borrow())); +} + +criterion_group!(benches, benchmarks); +criterion_main!(benches); |
