2023-09-20 13:15:28 -05:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
|
|
|
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
2023-09-20 19:35:37 -07:00
|
|
|
c.bench_function("parse + lex cube", |b| b.iter(|| lex_and_parse(CUBE_PROGRAM)));
|
|
|
|
c.bench_function("parse + lex big kitt", |b| {
|
|
|
|
b.iter(|| lex_and_parse(include_str!("../../tests/executor/inputs/kittycad_svg.kcl")))
|
|
|
|
});
|
2023-09-20 22:13:07 -05:00
|
|
|
c.bench_function("parse + lex pipes_on_pipes", |b| {
|
|
|
|
b.iter(|| lex_and_parse(include_str!("../../tests/executor/inputs/pipes_on_pipes.kcl")))
|
|
|
|
});
|
2023-09-20 13:15:28 -05:00
|
|
|
}
|
|
|
|
|
2023-09-20 19:35:37 -07:00
|
|
|
fn lex_and_parse(program: &str) {
|
|
|
|
let tokens = kcl_lib::tokeniser::lexer(program);
|
|
|
|
let parser = kcl_lib::parser::Parser::new(tokens);
|
|
|
|
parser.ast().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
|
|
criterion_main!(benches);
|
|
|
|
|
|
|
|
const CUBE_PROGRAM: &str = r#"fn cube = (pos, scale) => {
|
2023-09-20 13:15:28 -05:00
|
|
|
const sg = startSketchAt(pos)
|
|
|
|
|> line([0, scale], %)
|
|
|
|
|> line([scale, 0], %)
|
|
|
|
|> line([0, -scale], %)
|
|
|
|
|
|
|
|
return sg
|
|
|
|
}
|
|
|
|
|
|
|
|
const b1 = cube([0,0], 10)
|
|
|
|
const pt1 = b1[0]
|
|
|
|
show(b1)"#;
|