From 82b54928a06cefdbccb14a0541afb0daff3dfe91 Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Wed, 24 Apr 2024 11:59:16 -0400 Subject: [PATCH] test: add benches --- .vscode/tasks.json | 13 +++++++++++++ benches/bench.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 benches/bench.rs diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c56a070..e04b078 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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" + } } ] } diff --git a/benches/bench.rs b/benches/bench.rs new file mode 100644 index 0000000..6d18a1c --- /dev/null +++ b/benches/bench.rs @@ -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()); + } + }); +}