diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-09-21 17:50:58 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-21 20:25:57 +0200 |
| commit | ddd3b6a82b8c0353c942bfba8b89ca5476eedc58 (patch) | |
| tree | a64c350f0f1f82152ff18cfb02fbfdbf39292672 /benches | |
| parent | 3760748fddd3b793c79c370398a9d4a3fc5afc04 (diff) | |
Tracked memoization
Diffstat (limited to 'benches')
| -rw-r--r-- | benches/oneshot.rs | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/benches/oneshot.rs b/benches/oneshot.rs index 50fee9b1..23f829b3 100644 --- a/benches/oneshot.rs +++ b/benches/oneshot.rs @@ -1,5 +1,6 @@ use std::path::Path; +use comemo::{Prehashed, Track, Tracked}; use iai::{black_box, main, Iai}; use unscanny::Scanner; @@ -76,14 +77,16 @@ fn bench_highlight(iai: &mut Iai) { fn bench_eval(iai: &mut Iai) { let world = BenchWorld::new(); let id = world.source.id(); - iai.run(|| typst::eval::evaluate(&world, id, vec![]).unwrap()); + let route = typst::eval::Route::default(); + iai.run(|| typst::eval::eval(world.track(), route.track(), id).unwrap()); } fn bench_layout(iai: &mut Iai) { let world = BenchWorld::new(); let id = world.source.id(); - let module = typst::eval::evaluate(&world, id, vec![]).unwrap(); - iai.run(|| typst::model::layout(&world, &module.content)); + let route = typst::eval::Route::default(); + let module = typst::eval::eval(world.track(), route.track(), id).unwrap(); + iai.run(|| typst::model::layout(world.track(), &module.content)); } fn bench_render(iai: &mut Iai) { @@ -94,41 +97,38 @@ fn bench_render(iai: &mut Iai) { } struct BenchWorld { - config: Config, - book: FontBook, + config: Prehashed<Config>, + book: Prehashed<FontBook>, font: Font, source: Source, } impl BenchWorld { fn new() -> Self { + let config = Config::default(); let font = Font::new(FONT.into(), 0).unwrap(); let book = FontBook::from_fonts([&font]); - let id = SourceId::from_raw(0); + let id = SourceId::from_u16(0); let source = Source::new(id, Path::new("bench.typ"), TEXT.into()); Self { - config: Config::default(), - book, + config: Prehashed::new(config), + book: Prehashed::new(book), font, source, } } + + fn track(&self) -> Tracked<dyn World> { + (self as &dyn World).track() + } } impl World for BenchWorld { - fn config(&self) -> &Config { + fn config(&self) -> &Prehashed<Config> { &self.config } - fn resolve(&self, path: &Path) -> FileResult<SourceId> { - Err(FileError::NotFound(path.into())) - } - - fn source(&self, _: SourceId) -> &Source { - &self.source - } - - fn book(&self) -> &FontBook { + fn book(&self) -> &Prehashed<FontBook> { &self.book } @@ -139,4 +139,12 @@ impl World for BenchWorld { fn file(&self, path: &Path) -> FileResult<Buffer> { Err(FileError::NotFound(path.into())) } + + fn resolve(&self, path: &Path) -> FileResult<SourceId> { + Err(FileError::NotFound(path.into())) + } + + fn source(&self, _: SourceId) -> &Source { + &self.source + } } |
