diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/zerovec/benches/zerovec_iai.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/zerovec/benches/zerovec_iai.rs')
-rw-r--r-- | vendor/zerovec/benches/zerovec_iai.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/zerovec/benches/zerovec_iai.rs b/vendor/zerovec/benches/zerovec_iai.rs new file mode 100644 index 000000000..c34a6aebc --- /dev/null +++ b/vendor/zerovec/benches/zerovec_iai.rs @@ -0,0 +1,65 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +use iai::black_box; + +#[path = "../src/samples.rs"] +mod samples; +use samples::*; + +use zerovec::ule::VarULE; +use zerovec::VarZeroSlice; +use zerovec::ZeroVec; + +fn sum_slice() -> u32 { + black_box(TEST_SLICE).iter().sum::<u32>() +} + +fn sum_zerovec() -> u32 { + ZeroVec::<u32>::parse_byte_slice(black_box(TEST_BUFFER_LE)) + .unwrap() + .iter() + .sum::<u32>() +} + +fn binarysearch_slice() -> Result<usize, usize> { + black_box(TEST_SLICE).binary_search(&0x0c0d0c) +} + +fn binarysearch_zerovec() -> Result<usize, usize> { + ZeroVec::<u32>::parse_byte_slice(black_box(TEST_BUFFER_LE)) + .unwrap() + .binary_search(&0x0c0d0c) +} + +fn varzeroslice_parse_get() -> Option<&'static str> { + let slice: &'static VarZeroSlice<str> = + VarZeroSlice::parse_byte_slice(black_box(TEST_VARZEROSLICE_BYTES)).unwrap(); + slice.get(black_box(1)) +} + +fn varzeroslice_get() -> Option<&'static str> { + // Safety: The bytes are valid. + let slice: &'static VarZeroSlice<str> = + unsafe { VarZeroSlice::from_byte_slice_unchecked(black_box(TEST_VARZEROSLICE_BYTES)) }; + slice.get(black_box(1)) +} + +fn varzeroslice_get_unchecked() -> &'static str { + // Safety: The bytes are valid. + let slice: &'static VarZeroSlice<str> = + unsafe { VarZeroSlice::from_byte_slice_unchecked(black_box(TEST_VARZEROSLICE_BYTES)) }; + // Safety: The VarZeroVec has length 4. + unsafe { slice.get_unchecked(black_box(1)) } +} + +iai::main!( + sum_slice, + sum_zerovec, + binarysearch_slice, + binarysearch_zerovec, + varzeroslice_parse_get, + varzeroslice_get, + varzeroslice_get_unchecked, +); |