Separate benches for parsing and lexing
This commit is contained in:
@ -6,23 +6,28 @@ pub fn bench_lex(c: &mut Criterion) {
|
|||||||
c.bench_function("lex_pipes_on_pipes", |b| b.iter(|| lex(PIPES_PROGRAM)));
|
c.bench_function("lex_pipes_on_pipes", |b| b.iter(|| lex(PIPES_PROGRAM)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bench_lex_parse(c: &mut Criterion) {
|
pub fn bench_parse(c: &mut Criterion) {
|
||||||
c.bench_function("parse_lex_cube", |b| b.iter(|| lex_and_parse(CUBE_PROGRAM)));
|
for (name, file) in [
|
||||||
c.bench_function("parse_lex_big_kitt", |b| b.iter(|| lex_and_parse(KITT_PROGRAM)));
|
("pipes_on_pipes", PIPES_PROGRAM),
|
||||||
c.bench_function("parse_lex_pipes_on_pipes", |b| b.iter(|| lex_and_parse(PIPES_PROGRAM)));
|
("big_kitt", KITT_PROGRAM),
|
||||||
|
("cube", CUBE_PROGRAM),
|
||||||
|
] {
|
||||||
|
let tokens = kcl_lib::token::lexer(file);
|
||||||
|
c.bench_function(&format!("parse_{name}"), move |b| {
|
||||||
|
let tok = tokens.clone();
|
||||||
|
b.iter(move || {
|
||||||
|
let parser = kcl_lib::parser::Parser::new(tok.clone());
|
||||||
|
black_box(parser.ast().unwrap());
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lex(program: &str) {
|
fn lex(program: &str) {
|
||||||
black_box(kcl_lib::token::lexer(program));
|
black_box(kcl_lib::token::lexer(program));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lex_and_parse(program: &str) {
|
criterion_group!(benches, bench_lex, bench_parse);
|
||||||
let tokens = kcl_lib::token::lexer(program);
|
|
||||||
let parser = kcl_lib::parser::Parser::new(tokens);
|
|
||||||
black_box(parser.ast().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches, bench_lex, bench_lex_parse);
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|
||||||
const KITT_PROGRAM: &str = include_str!("../../tests/executor/inputs/kittycad_svg.kcl");
|
const KITT_PROGRAM: &str = include_str!("../../tests/executor/inputs/kittycad_svg.kcl");
|
||||||
|
|||||||
Reference in New Issue
Block a user