mirror of
https://github.com/gorules/zen.git
synced 2026-10-05 16:02:40 +00:00
* feat: expression static analysis * fix: cargo fmt * fix: python workflow * fix: python workflow * fix: python workflow * fix: ignore miri test bound by clock * fix: memory leaks
33 lines
867 B
Rust
33 lines
867 B
Rust
use bumpalo::Bump;
|
|
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
|
|
|
use zen_expression::lexer::Lexer;
|
|
use zen_expression::parser::Parser;
|
|
|
|
fn bench_source(b: &mut Bencher, src: &'static str) {
|
|
let mut lexer = Lexer::new();
|
|
let token_bump = Bump::new();
|
|
let mut bump = Bump::new();
|
|
let tokens = lexer.tokenize(&token_bump, src).unwrap();
|
|
|
|
b.iter(|| {
|
|
let unary_parser = Parser::try_new(&tokens, &bump).unwrap().unary();
|
|
criterion::black_box(unary_parser.parse());
|
|
|
|
bump.reset();
|
|
})
|
|
}
|
|
|
|
fn bench_functions(c: &mut Criterion) {
|
|
c.bench_function("unary/simple", |b| {
|
|
bench_source(b, "'hello world'");
|
|
});
|
|
|
|
c.bench_function("unary/large", |b| {
|
|
bench_source(b, "'a', 'b', 'c', 'd', 'e', 'f'")
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, bench_functions);
|
|
criterion_main!(benches);
|