-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use ordo::{eval, infer, parser::Parser}; | ||
|
||
pub fn eval_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("eval"); | ||
|
||
let expr = "let a = 1 in a"; | ||
group.bench_function(expr, |b| { | ||
b.iter(|| { | ||
let source = black_box(expr); | ||
let parsed = Parser::expr(source).unwrap(); | ||
let mut env = black_box(infer::Env::default()); | ||
let typed = env.infer(parsed).unwrap(); | ||
let mut env = black_box(eval::Env::default()); | ||
let result = env.eval(typed).unwrap(); | ||
black_box(result) | ||
}) | ||
}); | ||
|
||
let expr = "2 + 3 * 4"; | ||
group.bench_function(expr, |b| { | ||
b.iter(|| { | ||
let source = black_box(expr); | ||
let parsed = Parser::expr(source).unwrap(); | ||
let mut env = black_box(infer::Env::default()); | ||
let typed = env.infer(parsed).unwrap(); | ||
black_box(typed) | ||
}) | ||
}); | ||
|
||
let expr = "let add(a, b) = a + b in add(2, 3)"; | ||
group.bench_function(expr, |b| { | ||
b.iter(|| { | ||
let source = black_box(expr); | ||
let parsed = Parser::expr(source).unwrap(); | ||
let mut env = black_box(infer::Env::default()); | ||
let typed = env.infer(parsed).unwrap(); | ||
black_box(typed) | ||
}) | ||
}); | ||
|
||
let expr = "let add({a, b}) = a + b in let a = 2 in let b = 3 in add({a, b})"; | ||
group.bench_function(expr, |b| { | ||
b.iter(|| { | ||
let source = black_box(expr); | ||
let parsed = Parser::expr(source).unwrap(); | ||
let mut env = black_box(infer::Env::default()); | ||
let typed = env.infer(parsed).unwrap(); | ||
black_box(typed) | ||
}) | ||
}); | ||
|
||
let expr = | ||
"let safe_div(n, d) = if d == 0 then :div_by_zero {} else :ok (n / d) in safe_div(4, 2)"; | ||
group.bench_function(expr, |b| { | ||
b.iter(|| { | ||
let source = black_box(expr); | ||
let parsed = Parser::expr(source).unwrap(); | ||
let mut env = black_box(infer::Env::default()); | ||
let typed = env.infer(parsed).unwrap(); | ||
black_box(typed) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, eval_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters