Skip to content

Commit

Permalink
removed utils benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverKillane authored and nvzqz committed May 25, 2024
1 parent b93465a commit 5478a60
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 47 deletions.
46 changes: 39 additions & 7 deletions examples/benches/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,43 @@
//! cargo bench -q -p examples --bench collections
//! ```
use divan::{black_box, AllocProfiler, Bencher};
use std::collections::{BTreeSet, BinaryHeap, HashSet, LinkedList, VecDeque};

use divan::{AllocProfiler, Bencher};
pub fn collect_nums<T: FromIterator<i32>>(n: usize) -> T {
black_box(0..(n as i32)).collect()
}

pub trait WithCapacity {
fn with_capacity(c: usize) -> Self;
}

pub trait Clear {
fn clear(&mut self);
}

macro_rules! impl_with_capacity {
($($t:ident),+) => {
$(impl WithCapacity for $t<i32> {
fn with_capacity(c: usize) -> Self {
$t::with_capacity(c)
}
})+
};
}

macro_rules! impl_clear {
($($t:ident),+) => {
$(impl Clear for $t<i32> {
fn clear(&mut self) {
$t::clear(self);
}
})+
};
}

mod util;
impl_with_capacity!(Vec, VecDeque, BinaryHeap, HashSet);
impl_clear!(Vec, VecDeque, BinaryHeap, HashSet, LinkedList, BTreeSet);

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();
Expand Down Expand Up @@ -40,7 +72,7 @@ fn default<T: Default>() -> T {
],
args = LENS,
)]
fn with_capacity<T: util::WithCapacity>(bencher: Bencher, len: usize) {
fn with_capacity<T: WithCapacity>(bencher: Bencher, len: usize) {
bencher.counter(len).bench(|| T::with_capacity(len))
}

Expand All @@ -56,7 +88,7 @@ fn with_capacity<T: util::WithCapacity>(bencher: Bencher, len: usize) {
args = LENS,
)]
fn from_iter<T: FromIterator<i32>>(bencher: Bencher, len: usize) {
bencher.counter(len).bench(|| util::collect_nums::<T>(len))
bencher.counter(len).bench(|| collect_nums::<T>(len))
}

#[divan::bench(
Expand All @@ -71,7 +103,7 @@ fn from_iter<T: FromIterator<i32>>(bencher: Bencher, len: usize) {
args = LENS,
)]
fn drop<T: FromIterator<i32>>(bencher: Bencher, len: usize) {
bencher.counter(len).with_inputs(|| util::collect_nums::<T>(len)).bench_values(std::mem::drop);
bencher.counter(len).with_inputs(|| collect_nums::<T>(len)).bench_values(std::mem::drop);
}

#[divan::bench(
Expand All @@ -86,6 +118,6 @@ fn drop<T: FromIterator<i32>>(bencher: Bencher, len: usize) {
args = LENS,
max_time = 1,
)]
fn clear<T: FromIterator<i32> + util::Clear>(bencher: Bencher, len: usize) {
bencher.counter(len).with_inputs(|| util::collect_nums::<T>(len)).bench_refs(T::clear);
fn clear<T: FromIterator<i32> + Clear>(bencher: Bencher, len: usize) {
bencher.counter(len).with_inputs(|| collect_nums::<T>(len)).bench_refs(T::clear);
}
40 changes: 0 additions & 40 deletions examples/benches/util.rs

This file was deleted.

0 comments on commit 5478a60

Please sign in to comment.