diff --git a/Cargo.toml b/Cargo.toml index 871c8b8..71572f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] @@ -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 diff --git a/benches/rpds_list_triomphe.rs b/benches/rpds_list_triomphe.rs new file mode 100644 index 0000000..cef561a --- /dev/null +++ b/benches/rpds_list_triomphe.rs @@ -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 = 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 = 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 = 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 = 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 = 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 = 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 = 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);