diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/podio/benches/benchmark.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | third_party/rust/podio/benches/benchmark.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/third_party/rust/podio/benches/benchmark.rs b/third_party/rust/podio/benches/benchmark.rs new file mode 100644 index 0000000000..81614e75ec --- /dev/null +++ b/third_party/rust/podio/benches/benchmark.rs @@ -0,0 +1,49 @@ +// bench.rs +#![feature(test)] + +extern crate podio; +extern crate test; + +use test::Bencher; +use podio::{Endianness, BigEndian, LittleEndian, WritePodExt, ReadPodExt}; + +// bench: find the `BENCH_SIZE` first terms of the fibonacci sequence +const BENCH_SIZE: usize = 2000; + +#[bench] +fn write_u64_be(b: &mut Bencher) { + write_u64::<BigEndian>(b); +} + +#[bench] +fn write_u64_le(b: &mut Bencher) { + write_u64::<LittleEndian>(b); +} + +fn write_u64<T: Endianness>(b: &mut Bencher) { + b.iter(|| { + let mut writer : &mut[u8] = &mut [0; BENCH_SIZE * 8]; + for _ in 0..BENCH_SIZE { + writer.write_u64::<T>(0x012345678u64).unwrap(); + } + }) +} + +#[bench] +fn read_u64_be(b: &mut Bencher) { + read_u64::<BigEndian>(b); +} + +#[bench] +fn read_u64_le(b: &mut Bencher) { + read_u64::<LittleEndian>(b); +} + +fn read_u64<T: Endianness>(b: &mut Bencher) { + b.iter(|| { + let mut reader : &[u8] = &[0; BENCH_SIZE * 8]; + for _ in 0..BENCH_SIZE { + reader.read_u64::<T>().unwrap(); + } + }) +} |