mirror of
https://github.com/gorules/zen.git
synced 2026-10-05 00:02:26 +00:00
* temp: zen-expression rewrite * rewrite standard parser * stabilise parser, upgrade dependencies * implement unary parser * align builtin behavior * fix tests and minor bugs * refactor exports, update docs * fix expression repl * cleanup * cleanup vm * replace expression with expression-rewrite * update d.ts file * fix failing test
35 lines
991 B
Rust
35 lines
991 B
Rust
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
|
|
use serde_json::Value;
|
|
use zen_expression::Isolate;
|
|
|
|
fn bench_source(b: &mut Bencher, source: &'static str) {
|
|
let s: Value = serde_json::from_str(r#"{ "$": "ru" }"#).unwrap();
|
|
|
|
let mut isolate = Isolate::with_environment(&s);
|
|
b.iter(|| {
|
|
criterion::black_box(isolate.run_unary(source).unwrap());
|
|
})
|
|
}
|
|
|
|
fn bench_standard(b: &mut Bencher, source: &'static str) {
|
|
let s: Value = serde_json::from_str(r#"{ "$": "ru" }"#).unwrap();
|
|
|
|
let mut isolate = Isolate::with_environment(&s);
|
|
b.iter(|| {
|
|
criterion::black_box(isolate.run_standard(source).unwrap());
|
|
})
|
|
}
|
|
|
|
fn bench_functions(c: &mut Criterion) {
|
|
c.bench_function("isolate/simple", |b| {
|
|
bench_source(b, "'ru', 'se'");
|
|
});
|
|
|
|
c.bench_function("isolate/standard", |b| {
|
|
bench_standard(b, "contains(['ru', 'se'], $)");
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, bench_functions);
|
|
criterion_main!(benches);
|