Skip to content

Commit c0d1e32

Browse files
authored
Rollup merge of #107915 - JulianKnodt:array_benches, r=Mark-Simulacrum
Add `array::map` benchmarks Since there were no previous benchmarks for `array::map`, and it is known to have mediocre/poor performance, add some simple benchmarks. These benchmarks vary the length of the array and size of each item.
2 parents 4735829 + cbd1b81 commit c0d1e32

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: library/core/benches/array.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use test::black_box;
2+
use test::Bencher;
3+
4+
macro_rules! map_array {
5+
($func_name:ident, $start_item: expr, $map_item: expr, $arr_size: expr) => {
6+
#[bench]
7+
fn $func_name(b: &mut Bencher) {
8+
let arr = [$start_item; $arr_size];
9+
b.iter(|| black_box(arr).map(|_| black_box($map_item)));
10+
}
11+
};
12+
}
13+
14+
map_array!(map_8byte_8byte_8, 0u64, 1u64, 800);
15+
map_array!(map_8byte_8byte_64, 0u64, 1u64, 6400);
16+
map_array!(map_8byte_8byte_256, 0u64, 1u64, 25600);
17+
18+
map_array!(map_8byte_256byte_256, 0u64, [0u64; 4], 25600);
19+
map_array!(map_256byte_8byte_256, [0u64; 4], 0u64, 25600);

Diff for: library/core/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extern crate test;
1010

1111
mod any;
12+
mod array;
1213
mod ascii;
1314
mod char;
1415
mod fmt;

0 commit comments

Comments
 (0)