Skip to content

Commit

Permalink
test: add more benches
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 24, 2024
1 parent 82b5492 commit c8765e2
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use owned_ref_cell::OwnedRefCell;
use test::Bencher;

#[bench]
fn bench_owned_ref_cell_borrow_mut(b: &mut Bencher) {
fn bench_borrow_mut(b: &mut Bencher) {
let cell = OwnedRefCell::new(42);
b.iter(|| {
// Perform the mutable borrow inside the testing loop
Expand All @@ -16,7 +16,7 @@ fn bench_owned_ref_cell_borrow_mut(b: &mut Bencher) {
}

#[bench]
fn bench_owned_ref_cell_borrow(b: &mut Bencher) {
fn bench_borrow(b: &mut Bencher) {
let cell = OwnedRefCell::new(42);
b.iter(|| {
// Perform the immutable borrow inside the testing loop
Expand All @@ -25,3 +25,39 @@ fn bench_owned_ref_cell_borrow(b: &mut Bencher) {
}
});
}

#[bench]
fn bench_borrow_mut_borrow(b: &mut Bencher) {
let cell = OwnedRefCell::new(OwnedRefCell::new(42));
b.iter(|| {
let outer_borrow = cell.borrow_mut();
for _ in 0..1000 {
// Perform an inner borrow operation within an outer borrow
let _inner_borrow = outer_borrow.borrow();
}
});
}

#[bench]
fn bench_borrow_mut_borrow_mut(b: &mut Bencher) {
let cell = OwnedRefCell::new(OwnedRefCell::new(42));
b.iter(|| {
let outer_borrow = cell.borrow_mut();
for _ in 0..1000 {
// Perform an inner borrow operation within an outer borrow
let _inner_borrow = outer_borrow.try_borrow_mut();
}
});
}

#[bench]
fn bench_borrow_borrow_mut(b: &mut Bencher) {
let cell = OwnedRefCell::new(OwnedRefCell::new(42));
b.iter(|| {
let outer_borrow = cell.borrow();
for _ in 0..1000 {
// Perform an inner borrow operation within an outer borrow
let _inner_borrow = outer_borrow.try_borrow_mut();
}
});
}

0 comments on commit c8765e2

Please sign in to comment.