summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-14 19:54:49 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-14 19:54:49 +0200
commit0ac2e86feb09cabd11c93bad325ab4acead8ccbe (patch)
tree882571e9be6474e6782f5100e7044229e993cd4c
parent691423a40a3d3af0b938c3bfc3f89eedc0027c45 (diff)
Add basic parsing benchmark 🌩
-rw-r--r--Cargo.toml8
-rw-r--r--benches/bench_parsing.rs24
2 files changed, 31 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 53f6a2e2..0c39f487 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 00000000..d6b63caf
--- /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);