diff options
Diffstat (limited to 'bench/src')
| -rw-r--r-- | bench/src/clock.rs | 33 | ||||
| -rw-r--r-- | bench/src/parsing.rs | 7 |
2 files changed, 18 insertions, 22 deletions
diff --git a/bench/src/clock.rs b/bench/src/clock.rs index c3c5b378..7cd32711 100644 --- a/bench/src/clock.rs +++ b/bench/src/clock.rs @@ -4,7 +4,6 @@ use std::rc::Rc; use criterion::{criterion_group, criterion_main, Criterion}; -use typst::diag::Pass; use typst::eval::{eval, Module}; use typst::exec::exec; use typst::export::pdf; @@ -25,9 +24,9 @@ fn benchmarks(c: &mut Criterion) { for case in CASES { let path = Path::new(TYP_DIR).join(case); let name = path.file_stem().unwrap().to_string_lossy(); - let src_id = loader.resolve(&path).unwrap(); + let file = loader.resolve(&path).unwrap(); let src = std::fs::read_to_string(&path).unwrap(); - let case = Case::new(src_id, src, ctx.clone()); + let case = Case::new(file, src, ctx.clone()); macro_rules! bench { ($step:literal, setup = |$ctx:ident| $setup:expr, code = $code:expr $(,)?) => { @@ -80,7 +79,7 @@ fn benchmarks(c: &mut Criterion) { /// A test case with prepared intermediate results. struct Case { ctx: Rc<RefCell<Context>>, - src_id: FileId, + file: FileId, src: String, ast: Rc<SyntaxTree>, module: Module, @@ -89,16 +88,16 @@ struct Case { } impl Case { - fn new(src_id: FileId, src: String, ctx: Rc<RefCell<Context>>) -> Self { + fn new(file: FileId, src: String, ctx: Rc<RefCell<Context>>) -> Self { let mut borrowed = ctx.borrow_mut(); - let ast = Rc::new(parse(&src).output); - let module = eval(&mut borrowed, src_id, Rc::clone(&ast)).output; - let tree = exec(&mut borrowed, &module.template).output; + let ast = Rc::new(parse(file, &src).unwrap()); + let module = eval(&mut borrowed, file, Rc::clone(&ast)).unwrap(); + let tree = exec(&mut borrowed, &module.template); let frames = layout(&mut borrowed, &tree); drop(borrowed); Self { ctx, - src_id, + file, src, ast, module, @@ -108,18 +107,14 @@ impl Case { } fn parse(&self) -> SyntaxTree { - parse(&self.src).output + parse(self.file, &self.src).unwrap() } - fn eval(&self) -> Pass<Module> { - eval( - &mut self.ctx.borrow_mut(), - self.src_id, - Rc::clone(&self.ast), - ) + fn eval(&self) -> Module { + eval(&mut self.ctx.borrow_mut(), self.file, Rc::clone(&self.ast)).unwrap() } - fn exec(&self) -> Pass<LayoutTree> { + fn exec(&self) -> LayoutTree { exec(&mut self.ctx.borrow_mut(), &self.module.template) } @@ -127,8 +122,8 @@ impl Case { layout(&mut self.ctx.borrow_mut(), &self.tree) } - fn typeset(&self) -> Pass<Vec<Rc<Frame>>> { - self.ctx.borrow_mut().typeset(self.src_id, &self.src) + fn typeset(&self) -> Vec<Rc<Frame>> { + self.ctx.borrow_mut().typeset(self.file, &self.src).unwrap() } fn pdf(&self) -> Vec<u8> { diff --git a/bench/src/parsing.rs b/bench/src/parsing.rs index d34faf62..d9064a63 100644 --- a/bench/src/parsing.rs +++ b/bench/src/parsing.rs @@ -1,6 +1,7 @@ use iai::{black_box, main}; -use typst::diag::Pass; +use typst::diag::TypResult; +use typst::loading::FileId; use typst::parse::{parse, Scanner, TokenMode, Tokens}; use typst::syntax::SyntaxTree; @@ -30,8 +31,8 @@ fn bench_tokenize() -> usize { Tokens::new(black_box(SRC), black_box(TokenMode::Markup)).count() } -fn bench_parse() -> Pass<SyntaxTree> { - parse(black_box(SRC)) +fn bench_parse() -> TypResult<SyntaxTree> { + parse(FileId::from_raw(0), black_box(SRC)) } main!(bench_decode, bench_scan, bench_tokenize, bench_parse); |
