From c8765e248e2eb4a892d936bb0e128227966d1a77 Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Wed, 24 Apr 2024 12:21:28 -0400 Subject: [PATCH] test: add more benches --- benches/bench.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 6d18a1c..765d0e5 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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 @@ -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 @@ -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(); + } + }); +}