Skip to content

Commit

Permalink
Rough benchmarks (a feature might be better)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Oct 24, 2023
1 parent 6df660a commit 8dd589a
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ include = [
codecov = { repository = "orium/rpds", branch = "master", service = "github" }

[dependencies]
archery = "1.0.0"
# FIXME: use release
# archery = "1.0.0"
archery = { git = "https://github.com/michaelsproul/archery", branch = "triomphe", features = ["triomphe"] }
serde = { version = "1.0.149", optional = true, default-features = false }

[dev-dependencies]
Expand Down Expand Up @@ -70,6 +72,10 @@ harness = false
name = "rpds_list_sync"
harness = false

[[bench]]
name = "rpds_list_triomphe"
harness = false

[[bench]]
name = "std_vec"
harness = false
Expand Down
172 changes: 172 additions & 0 deletions benches/rpds_list_triomphe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#![cfg_attr(feature = "fatal-warnings", deny(warnings))]

use archery::ArcTK;
use criterion::{criterion_group, criterion_main, Criterion};
use rpds::List;
use std::hint::black_box;

fn rpds_list_triomphe_push_front(c: &mut Criterion) {
let limit = 10_000;

c.bench_function("rpds list sync push front", move |b| {
b.iter(|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list = list.push_front(i);
}

list
})
});
}

fn rpds_list_triomphe_push_front_mut(c: &mut Criterion) {
let limit = 10_000;

c.bench_function("rpds list sync push front mut", move |b| {
b.iter(|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

list
})
});
}

fn rpds_list_triomphe_drop_first(c: &mut Criterion) {
let limit = 10_000;

c.bench_function("rpds list sync drop first", move |b| {
b.iter_with_setup(
|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

list
},
|mut list| {
for _ in 0..limit {
list = list.drop_first().unwrap();
}

list
},
);
});
}

fn rpds_list_triomphe_drop_first_mut(c: &mut Criterion) {
let limit = 10_000;

c.bench_function("rpds list sync drop first mut", move |b| {
b.iter_with_setup(
|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

list
},
|mut list| {
for _ in 0..limit {
list.drop_first_mut();
}

list
},
);
});
}

fn rpds_list_triomphe_reverse(c: &mut Criterion) {
let limit = 1_000;

c.bench_function("rpds list sync reverse", move |b| {
b.iter_with_setup(
|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

list
},
|mut list| {
for _ in 0..limit {
list = list.reverse();
}

list
},
);
});
}

fn rpds_list_triomphe_reverse_mut(c: &mut Criterion) {
let limit = 1_000;

c.bench_function("rpds list sync reverse mut", move |b| {
b.iter_with_setup(
|| {
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

list
},
|mut list| {
for _ in 0..limit {
list.reverse_mut();
}

list
},
);
});
}

fn rpds_list_triomphe_iterate(c: &mut Criterion) {
let limit = 10_000;
let mut list: List<usize, ArcTK> = List::new_with_ptr_kind();

for i in 0..limit {
list.push_front_mut(i);
}

c.bench_function("rpds list sync iterate", move |b| {
b.iter(|| {
for i in list.iter() {
black_box(i);
}
})
});
}

criterion_group!(
benches,
rpds_list_triomphe_push_front,
rpds_list_triomphe_push_front_mut,
rpds_list_triomphe_drop_first,
rpds_list_triomphe_drop_first_mut,
rpds_list_triomphe_reverse,
rpds_list_triomphe_reverse_mut,
rpds_list_triomphe_iterate
);
criterion_main!(benches);

0 comments on commit 8dd589a

Please sign in to comment.