summaryrefslogtreecommitdiff
path: root/benches
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2021-11-28 18:18:45 +0100
committerMartin Haug <mhaug@live.de>2021-11-28 18:18:45 +0100
commite05eb5fda5d1dfeef168b6fc071b20fdbcce2dcd (patch)
tree6b4585c065ce21a76784cd0915d9b6e0a414f88d /benches
parentedc686d7384470068858e16f2926cf50f31b2c90 (diff)
Code Review: Parser, I can't let you do this
Diffstat (limited to 'benches')
-rw-r--r--benches/timed.rs98
1 files changed, 0 insertions, 98 deletions
diff --git a/benches/timed.rs b/benches/timed.rs
deleted file mode 100644
index 83820af2..00000000
--- a/benches/timed.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-use std::path::Path;
-
-use criterion::{black_box, criterion_group, criterion_main, Criterion};
-
-use typst::eval::eval;
-use typst::layout::layout;
-use typst::loading::MemLoader;
-use typst::parse::{parse, Scanner, TokenMode, Tokens};
-use typst::source::SourceId;
-use typst::Context;
-
-const SRC: &str = include_str!("bench.typ");
-const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf");
-
-fn context() -> (Context, SourceId) {
- let loader = MemLoader::new().with(Path::new("font.ttf"), FONT).wrap();
- let mut ctx = Context::new(loader);
- let id = ctx.sources.provide(Path::new("src.typ"), SRC.to_string());
- (ctx, id)
-}
-
-fn bench_decode(c: &mut Criterion) {
- c.bench_function("decode", |b| {
- b.iter(|| {
- // We don't use chars().count() because that has a special
- // superfast implementation.
- let mut count = 0;
- let mut chars = black_box(SRC).chars();
- while let Some(_) = chars.next() {
- count += 1;
- }
- count
- })
- });
-}
-
-fn bench_scan(c: &mut Criterion) {
- c.bench_function("scan", |b| {
- b.iter(|| {
- let mut count = 0;
- let mut scanner = Scanner::new(black_box(SRC));
- while let Some(_) = scanner.eat() {
- count += 1;
- }
- count
- })
- });
-}
-
-fn bench_tokenize(c: &mut Criterion) {
- c.bench_function("tokenize", |b| {
- b.iter(|| Tokens::new(black_box(SRC), black_box(TokenMode::Markup)).count())
- });
-}
-
-fn bench_parse(c: &mut Criterion) {
- c.bench_function("parse", |b| b.iter(|| parse(SRC)));
-}
-
-fn bench_edit(c: &mut Criterion) {
- let (mut ctx, id) = context();
- c.bench_function("edit", |b| {
- b.iter(|| black_box(ctx.sources.edit(id, 1168 .. 1171, "_Uhr_")))
- });
-}
-
-fn bench_eval(c: &mut Criterion) {
- let (mut ctx, id) = context();
- let ast = ctx.sources.get(id).ast().unwrap();
- c.bench_function("eval", |b| b.iter(|| eval(&mut ctx, id, &ast).unwrap()));
-}
-
-fn bench_to_tree(c: &mut Criterion) {
- let (mut ctx, id) = context();
- let module = ctx.evaluate(id).unwrap();
- c.bench_function("to_tree", |b| {
- b.iter(|| module.template.to_pages(ctx.style()))
- });
-}
-
-fn bench_layout(c: &mut Criterion) {
- let (mut ctx, id) = context();
- let tree = ctx.execute(id).unwrap();
- c.bench_function("layout", |b| b.iter(|| layout(&mut ctx, &tree)));
-}
-
-criterion_group!(
- benches,
- bench_decode,
- bench_scan,
- bench_tokenize,
- bench_parse,
- bench_edit,
- bench_eval,
- bench_to_tree,
- bench_layout
-);
-criterion_main!(benches);