mirror of
https://github.com/typst/typst
synced 2025-05-21 04:25:28 +08:00
New shiny benchmarks with iai!
This commit is contained in:
parent
9fe9b95b7f
commit
0481192a77
@ -11,9 +11,15 @@ layout-cache = ["typst/layout-cache"]
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.3", features = ["html_reports"] }
|
criterion = { version = "0.3", features = ["html_reports"] }
|
||||||
|
iai = "0.1"
|
||||||
typst = { path = "..", default-features = false, features = ["fs"] }
|
typst = { path = "..", default-features = false, features = ["fs"] }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "typst"
|
name = "clock"
|
||||||
path = "src/bench.rs"
|
path = "src/clock.rs"
|
||||||
|
harness = false
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "parsing"
|
||||||
|
path = "src/parsing.rs"
|
||||||
harness = false
|
harness = false
|
||||||
|
37
bench/src/parsing.rs
Normal file
37
bench/src/parsing.rs
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user