mirror of
https://github.com/gorules/zen.git
synced 2026-10-06 08:02:18 +00:00
* local: fault tolerant parser * fix tests * add intellisense * fix minor issues * improve support * fix fmt * fix * fix: improve error messages * improve error handling and ast * fix lint * fix tests * exclude zen-nodejs from rust tests
32 lines
819 B
Rust
32 lines
819 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 mut bump = Bump::new();
|
|
let tokens = lexer.tokenize(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);
|