Skip to content

Commit

Permalink
test: add benches
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 24, 2024
1 parent 0808fdf commit 82b5492
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
"kind": "test",
"isDefault": "true"
}
},
{
"label": "bench",
"type": "shell",
"command": "cargo bench",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": "false"
}
}
]
}
27 changes: 27 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![feature(test)]

extern crate test;
use owned_ref_cell::OwnedRefCell;
use test::Bencher;

#[bench]
fn bench_owned_ref_cell_borrow_mut(b: &mut Bencher) {
let cell = OwnedRefCell::new(42);
b.iter(|| {
// Perform the mutable borrow inside the testing loop
for _ in 0..1000 {
test::black_box(cell.try_borrow_mut());
}
});
}

#[bench]
fn bench_owned_ref_cell_borrow(b: &mut Bencher) {
let cell = OwnedRefCell::new(42);
b.iter(|| {
// Perform the immutable borrow inside the testing loop
for _ in 0..1000 {
test::black_box(cell.try_borrow());
}
});
}

0 comments on commit 82b5492

Please sign in to comment.