Skip to content

Commit

Permalink
Rollup merge of #107915 - JulianKnodt:array_benches, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan-DPC committed Feb 13, 2023
2 parents 4735829 + cbd1b81 commit c0d1e32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/core/benches/array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use test::black_box;
use test::Bencher;

macro_rules! map_array {
($func_name:ident, $start_item: expr, $map_item: expr, $arr_size: expr) => {
#[bench]
fn $func_name(b: &mut Bencher) {
let arr = [$start_item; $arr_size];
b.iter(|| black_box(arr).map(|_| black_box($map_item)));
}
};
}

map_array!(map_8byte_8byte_8, 0u64, 1u64, 800);
map_array!(map_8byte_8byte_64, 0u64, 1u64, 6400);
map_array!(map_8byte_8byte_256, 0u64, 1u64, 25600);

map_array!(map_8byte_256byte_256, 0u64, [0u64; 4], 25600);
map_array!(map_256byte_8byte_256, [0u64; 4], 0u64, 25600);
1 change: 1 addition & 0 deletions library/core/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
extern crate test;

mod any;
mod array;
mod ascii;
mod char;
mod fmt;
Expand Down

0 comments on commit c0d1e32

Please sign in to comment.