2023-09-22 21:01:18 -05:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
|
|
|
|
|
|
pub fn bench_lex(c: &mut Criterion) {
|
|
|
|
c.bench_function("lex_cube", |b| b.iter(|| lex(CUBE_PROGRAM)));
|
|
|
|
c.bench_function("lex_big_kitt", |b| b.iter(|| lex(KITT_PROGRAM)));
|
|
|
|
c.bench_function("lex_pipes_on_pipes", |b| b.iter(|| lex(PIPES_PROGRAM)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bench_lex_parse(c: &mut Criterion) {
|
|
|
|
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(KITT_PROGRAM)));
|
|
|
|
c.bench_function("parse_lex_pipes_on_pipes", |b| b.iter(|| lex_and_parse(PIPES_PROGRAM)));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lex(program: &str) {
|
|
|
|
black_box(kcl_lib::tokeniser::lexer(program));
|
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);
|
2023-09-22 21:01:18 -05:00
|
|
|
black_box(parser.ast().unwrap());
|
2023-09-20 19:35:37 -07:00
|
|
|
}
|
|
|
|
|
2023-09-22 21:01:18 -05:00
|
|
|
criterion_group!(benches, bench_lex, bench_lex_parse);
|
2023-09-20 19:35:37 -07:00
|
|
|
criterion_main!(benches);
|
|
|
|
|
2023-09-22 21:01:18 -05:00
|
|
|
const KITT_PROGRAM: &str = include_str!("../../tests/executor/inputs/kittycad_svg.kcl");
|
|
|
|
const PIPES_PROGRAM: &str = include_str!("../../tests/executor/inputs/pipes_on_pipes.kcl");
|
2023-09-20 19:35:37 -07:00
|
|
|
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)"#;
|