Skip to content

Commit 6a56ed4

Browse files
committed
chore: Add an identity benchmark for function calls
1 parent a60a444 commit 6a56ed4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

benches/function_call.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ use gluon::{
1010
};
1111

1212
// Benchmarks function calls
13+
14+
fn identity(b: &mut Bencher) {
15+
let vm = new_vm();
16+
let text = r#"
17+
let id x = x
18+
id
19+
"#;
20+
vm.load_script("id", text).unwrap();
21+
let mut id: FunctionRef<fn(i32) -> i32> = vm.get_global("id").unwrap();
22+
b.iter(|| {
23+
let result = id.call(20).unwrap();
24+
black_box(result)
25+
})
26+
}
27+
1328
fn factorial(b: &mut Bencher) {
1429
let vm = new_vm();
1530
let text = r#"
@@ -81,6 +96,7 @@ fn gluon_rust_boundary_overhead(b: &mut Bencher) {
8196
}
8297

8398
fn function_call_benchmark(c: &mut Criterion) {
99+
c.bench_function("identity", identity);
84100
c.bench_function("factorial", factorial);
85101
c.bench_function("factorial tail call", factorial_tail_call);
86102
c.bench_function("gluon rust boundary overhead", gluon_rust_boundary_overhead);

0 commit comments

Comments
 (0)