Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 42 additions & 19 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#![allow(deprecated)]

use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use smallvec::{smallvec, SmallVec};
use std::hint::black_box;
use std::time::Duration;
use {
criterion::{
Bencher,
Criterion,
criterion_group,
criterion_main
},
smallvec::{
SmallVec,
smallvec
},
std::{
hint::black_box,
time::Duration
}
};

const VEC_SIZE: usize = 16;
const SPILLED_SIZE: usize = 100;
Expand All @@ -18,39 +30,44 @@ trait Vector<T>: for<'a> From<&'a [T]> + Extend<T> {
fn from_elems(val: &[T]) -> Self;
fn extend_from_slice(&mut self, other: &[T]);
fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool;
where F: FnMut(&mut T) -> bool;
}

impl<T: Copy> Vector<T> for Vec<T> {
fn new() -> Self {
Self::with_capacity(VEC_SIZE)
}

fn push(&mut self, val: T) {
self.push(val)
}

fn pop(&mut self) -> Option<T> {
self.pop()
}

fn remove(&mut self, p: usize) -> T {
self.remove(p)
}

fn insert(&mut self, n: usize, val: T) {
self.insert(n, val)
}

fn from_elem(val: T, n: usize) -> Self {
vec![val; n]
}

fn from_elems(val: &[T]) -> Self {
val.to_owned()
}

fn extend_from_slice(&mut self, other: &[T]) {
Vec::extend_from_slice(self, other)
}

fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool,
{
where F: FnMut(&mut T) -> bool {
self.retain_mut(f)
}
}
Expand All @@ -59,31 +76,37 @@ impl<T: Copy> Vector<T> for SmallVec<T, VEC_SIZE> {
fn new() -> Self {
Self::new()
}

fn push(&mut self, val: T) {
self.push(val)
}

fn pop(&mut self) -> Option<T> {
self.pop()
}

fn remove(&mut self, p: usize) -> T {
self.remove(p)
}

fn insert(&mut self, n: usize, val: T) {
self.insert(n, val)
}

fn from_elem(val: T, n: usize) -> Self {
smallvec![val; n]
}

fn from_elems(val: &[T]) -> Self {
SmallVec::from(val)
}

fn extend_from_slice(&mut self, other: &[T]) {
SmallVec::extend_from_slice(self, other)
}

fn retain_mut<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool,
{
where F: FnMut(&mut T) -> bool {
self.retain_mut(f)
}
}
Expand All @@ -100,8 +123,8 @@ macro_rules! make_benches {
}
}

/* ---------- Bench generation (same list, just using the new macro)
* ---------- */
// ---------- Bench generation (same list, just using the new macro)
// ----------
make_benches! {
SmallVec<u64, VEC_SIZE> {
bench_push => gen_push(SPILLED_SIZE as _),
Expand Down Expand Up @@ -216,7 +239,7 @@ fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {
insert_noinline(&mut vec, 0, x);
}
vec
},
}
);
}

Expand All @@ -233,7 +256,7 @@ fn gen_remove<V: Vector<u64>>(n: usize, b: &mut Bencher) {
black_box(remove_noinline(&mut vec, 0));
}
vec
},
}
);
}

Expand Down Expand Up @@ -309,7 +332,7 @@ fn gen_retain_mut_half<V: Vector<u64>>(n: usize, b: &mut Bencher) {
|mut vec| {
vec.retain_mut(|x| black_box(*x) % 2 == 0);
vec
},
}
);
}

Expand All @@ -319,7 +342,7 @@ fn gen_retain_mut_all<V: Vector<u64>>(n: usize, b: &mut Bencher) {
|mut vec| {
vec.retain_mut(|_| true);
vec
},
}
);
}

Expand All @@ -329,7 +352,7 @@ fn gen_retain_mut_none<V: Vector<u64>>(n: usize, b: &mut Bencher) {
|mut vec| {
vec.retain_mut(|_| false);
vec
},
}
);
}

Expand Down
17 changes: 15 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
wrap_comments = true
imports_granularity = "Preserve"
imports_granularity = "One"
group_imports = "One"
format_code_in_doc_comments = true
format_code_in_doc_comments = true
error_on_line_overflow = true
error_on_unformatted = true
blank_lines_lower_bound = 0
blank_lines_upper_bound = 1
float_literal_trailing_zero = "IfNoPostfix"
imports_layout = "Vertical"
normalize_comments = true
reorder_impl_items = true
struct_lit_single_line = false
style_edition = "2024"
trailing_comma = "Never"
use_try_shorthand = true
where_single_line = true
Loading
Loading