summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-13 15:11:06 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-13 15:18:34 +0200
commit0481192a77f953e3bef727326bd93413f709c447 (patch)
treeeb1354df364e6cbaffac745122c216cacd69a6b8
parent9fe9b95b7f257100b9242913ae079752b232bb87 (diff)
New shiny benchmarks with iai!
-rw-r--r--bench/Cargo.toml10
-rw-r--r--bench/src/clock.rs (renamed from bench/src/bench.rs)0
-rw-r--r--bench/src/parsing.rs37
3 files changed, 45 insertions, 2 deletions
diff --git a/bench/Cargo.toml b/bench/Cargo.toml
index 260a2ba1..eec8a96e 100644
--- a/bench/Cargo.toml
+++ b/bench/Cargo.toml
@@ -11,9 +11,15 @@ layout-cache = ["typst/layout-cache"]
[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
+iai = "0.1"
typst = { path = "..", default-features = false, features = ["fs"] }
[[bench]]
-name = "typst"
-path = "src/bench.rs"
+name = "clock"
+path = "src/clock.rs"
+harness = false
+
+[[bench]]
+name = "parsing"
+path = "src/parsing.rs"
harness = false
diff --git a/bench/src/bench.rs b/bench/src/clock.rs
index 129215fe..129215fe 100644
--- a/bench/src/bench.rs
+++ b/bench/src/clock.rs
diff --git a/bench/src/parsing.rs b/bench/src/parsing.rs
new file mode 100644
index 00000000..d34faf62
--- /dev/null
+++ b/bench/src/parsing.rs
@@ -0,0 +1,37 @@
+use iai::{black_box, main};
+
+use typst::diag::Pass;
+use typst::parse::{parse, Scanner, TokenMode, Tokens};
+use typst::syntax::SyntaxTree;
+
+const SRC: &str = include_str!("../../tests/typ/coma.typ");
+
+fn bench_decode() -> usize {
+ // 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() -> usize {
+ let mut count = 0;
+ let mut scanner = Scanner::new(black_box(SRC));
+ while let Some(_) = scanner.eat() {
+ count += 1;
+ }
+ count
+}
+
+fn bench_tokenize() -> usize {
+ Tokens::new(black_box(SRC), black_box(TokenMode::Markup)).count()
+}
+
+fn bench_parse() -> Pass<SyntaxTree> {
+ parse(black_box(SRC))
+}
+
+main!(bench_decode, bench_scan, bench_tokenize, bench_parse);