-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rough benchmarks (a feature might be better)
- Loading branch information
1 parent
6df660a
commit 8dd589a
Showing
2 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |