From 0ac2e86feb09cabd11c93bad325ab4acead8ccbe Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 14 Aug 2020 19:54:49 +0200 Subject: [PATCH] =?UTF-8?q?Add=20basic=20parsing=20benchmark=20?= =?UTF-8?q?=F0=9F=8C=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 8 +++++++- benches/bench_parsing.rs | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 benches/bench_parsing.rs diff --git a/Cargo.toml b/Cargo.toml index 53f6a2e21..0c39f4876 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,12 +23,18 @@ serialize = [] fs = ["fontdock/fs"] [dev-dependencies] +criterion = "0.3" futures-executor = "0.3" serde_json = "1" raqote = { version = "0.8", default-features = false } [[test]] -name = "test-typeset" +name = "typeset" path = "tests/test_typeset.rs" required-features = ["fs"] harness = false + +[[bench]] +name = "bench-parsing" +path = "benches/bench_parsing.rs" +harness = false diff --git a/benches/bench_parsing.rs b/benches/bench_parsing.rs new file mode 100644 index 000000000..d6b63cafc --- /dev/null +++ b/benches/bench_parsing.rs @@ -0,0 +1,24 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use typstc::library::_std; +use typstc::syntax::parsing::{parse, ParseState}; +use typstc::syntax::span::Pos; + +// 28 not too dense lines. +const COMA: &str = include_str!("../tests/coma.typ"); + +fn parsing_benchmark(c: &mut Criterion) { + let state = ParseState { scope: _std() }; + + c.bench_function("parse-coma-28-lines", |b| { + b.iter(|| parse(COMA, Pos::ZERO, &state)) + }); + + // 2800 lines of Typst code. + let long = COMA.repeat(100); + c.bench_function("parse-coma-2800-lines", |b| { + b.iter(|| parse(&long, Pos::ZERO, &state)) + }); +} + +criterion_group!(benches, parsing_benchmark); +criterion_main!(benches);