diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/hex/benches | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/hex/benches')
-rw-r--r-- | third_party/rust/hex/benches/hex.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/third_party/rust/hex/benches/hex.rs b/third_party/rust/hex/benches/hex.rs new file mode 100644 index 0000000000..6435032c64 --- /dev/null +++ b/third_party/rust/hex/benches/hex.rs @@ -0,0 +1,61 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use rustc_hex::{FromHex, ToHex}; + +const DATA: &[u8] = include_bytes!("../src/lib.rs"); + +fn bench_encode(c: &mut Criterion) { + c.bench_function("hex_encode", |b| b.iter(|| hex::encode(DATA))); + + c.bench_function("rustc_hex_encode", |b| b.iter(|| DATA.to_hex::<String>())); + + c.bench_function("faster_hex_encode", |b| { + b.iter(|| faster_hex::hex_string(DATA).unwrap()) + }); + + c.bench_function("faster_hex_encode_fallback", |b| { + b.iter(|| { + let mut dst = vec![0; DATA.len() * 2]; + faster_hex::hex_encode_fallback(DATA, &mut dst); + dst + }) + }); +} + +fn bench_decode(c: &mut Criterion) { + c.bench_function("hex_decode", |b| { + let hex = hex::encode(DATA); + b.iter(|| hex::decode(&hex).unwrap()) + }); + + c.bench_function("rustc_hex_decode", |b| { + let hex = DATA.to_hex::<String>(); + b.iter(|| hex.from_hex::<Vec<u8>>().unwrap()) + }); + + c.bench_function("faster_hex_decode", move |b| { + let hex = faster_hex::hex_string(DATA).unwrap(); + let len = DATA.len(); + let mut dst = vec![0; len]; + + b.iter(|| faster_hex::hex_decode(hex.as_bytes(), &mut dst).unwrap()) + }); + + c.bench_function("faster_hex_decode_unchecked", |b| { + let hex = faster_hex::hex_string(DATA).unwrap(); + let len = DATA.len(); + let mut dst = vec![0; len]; + + b.iter(|| faster_hex::hex_decode_unchecked(hex.as_bytes(), &mut dst)) + }); + + c.bench_function("faster_hex_decode_fallback", |b| { + let hex = faster_hex::hex_string(DATA).unwrap(); + let len = DATA.len(); + let mut dst = vec![0; len]; + + b.iter(|| faster_hex::hex_decode_fallback(hex.as_bytes(), &mut dst)) + }); +} + +criterion_group!(benches, bench_encode, bench_decode); +criterion_main!(benches); |