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/uuid/benches | |
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 'third_party/rust/uuid/benches')
-rw-r--r-- | third_party/rust/uuid/benches/format_str.rs | 66 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/invalid_parse_str.rs | 58 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/mod.rs | 4 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/serde_support.rs | 48 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/slog_support/mod.rs | 1 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/slog_support/parse_str.rs | 15 | ||||
-rw-r--r-- | third_party/rust/uuid/benches/valid_parse_str.rs | 39 |
7 files changed, 231 insertions, 0 deletions
diff --git a/third_party/rust/uuid/benches/format_str.rs b/third_party/rust/uuid/benches/format_str.rs new file mode 100644 index 0000000000..f029cf03d1 --- /dev/null +++ b/third_party/rust/uuid/benches/format_str.rs @@ -0,0 +1,66 @@ +#![feature(test)] +extern crate test; + +use std::io::Write; +use test::Bencher; +use uuid::Uuid; + +#[bench] +fn bench_hyphen(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 36]; + write!(&mut buffer as &mut [_], "{:x}", uuid.to_hyphenated()).unwrap(); + test::black_box(buffer); + }); +} + +#[bench] +fn bench_simple(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 32]; + write!(&mut buffer as &mut [_], "{:x}", uuid.to_simple()).unwrap(); + test::black_box(buffer); + }) +} + +#[bench] +fn bench_urn(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 36 + 9]; + write!(&mut buffer as &mut [_], "{:x}", uuid.to_urn()).unwrap(); + test::black_box(buffer); + }) +} + +#[bench] +fn bench_encode_hyphen(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 36]; + uuid.to_hyphenated().encode_lower(&mut buffer); + test::black_box(buffer); + }); +} + +#[bench] +fn bench_encode_simple(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 32]; + uuid.to_simple().encode_lower(&mut buffer); + test::black_box(buffer); + }) +} + +#[bench] +fn bench_encode_urn(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + b.iter(|| { + let mut buffer = [0_u8; 36 + 9]; + uuid.to_urn().encode_lower(&mut buffer); + test::black_box(buffer); + }) +} diff --git a/third_party/rust/uuid/benches/invalid_parse_str.rs b/third_party/rust/uuid/benches/invalid_parse_str.rs new file mode 100644 index 0000000000..7fde28b3bb --- /dev/null +++ b/third_party/rust/uuid/benches/invalid_parse_str.rs @@ -0,0 +1,58 @@ +#![feature(test)] +extern crate test; + +use test::Bencher; +use uuid::Uuid; + +#[bench] +fn bench_parse_invalid_strings(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str(""); + let _ = Uuid::parse_str("!"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E45"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faaXB6BFF329BF39FA1E4"); + let _ = Uuid::parse_str("F9168C5E-CEB-24fa-eB6BFF32-BF39FA1E4"); + let _ = Uuid::parse_str("01020304-1112-2122-3132-41424344"); + let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c88"); + let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0cg8"); + let _ = Uuid::parse_str("67e5504410b1426%9247bb680e5fe0c8"); + + // Test error reporting + let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c"); + let _ = Uuid::parse_str("67e550X410b1426f9247bb680e5fe0cd"); + let _ = Uuid::parse_str("67e550-4105b1426f9247bb680e5fe0c"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF1-02BF39FA1E4"); + }); +} + +#[bench] +fn bench_parse_invalid_len(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); + }) +} + +#[bench] +fn bench_parse_invalid_character(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); + }) +} + +#[bench] +fn bench_parse_invalid_group_len(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("01020304-1112-2122-3132-41424344"); + }); +} + +#[bench] +fn bench_parse_invalid_groups(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); + }); +} diff --git a/third_party/rust/uuid/benches/mod.rs b/third_party/rust/uuid/benches/mod.rs new file mode 100644 index 0000000000..2ef574f012 --- /dev/null +++ b/third_party/rust/uuid/benches/mod.rs @@ -0,0 +1,4 @@ +#![feature(test)] + +#[cfg(feature = "slog")] +pub mod slog_support; diff --git a/third_party/rust/uuid/benches/serde_support.rs b/third_party/rust/uuid/benches/serde_support.rs new file mode 100644 index 0000000000..a7ce64f824 --- /dev/null +++ b/third_party/rust/uuid/benches/serde_support.rs @@ -0,0 +1,48 @@ +#![cfg(feature = "serde")] +#![feature(test)] + +use bincode; +use serde_json; +extern crate test; + +use test::Bencher; +use uuid::Uuid; + +#[bench] +fn bench_json_encode(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + let mut buffer = [0_u8; 38]; + b.iter(|| { + serde_json::to_writer(&mut buffer as &mut [u8], &uuid).unwrap(); + test::black_box(buffer); + }); + b.bytes = buffer.len() as u64; +} + +#[bench] +fn bench_json_decode(b: &mut Bencher) { + let s = "\"F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4\""; + b.iter(|| serde_json::from_str::<Uuid>(s).unwrap()); + b.bytes = s.len() as u64; +} + +#[bench] +fn bench_bincode_encode(b: &mut Bencher) { + let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); + let mut buffer = [0_u8; 24]; + b.iter(|| { + bincode::serialize_into(&mut buffer as &mut [u8], &uuid).unwrap(); + test::black_box(buffer); + }); + b.bytes = buffer.len() as u64; +} + +#[bench] +fn bench_bincode_decode(b: &mut Bencher) { + let bytes = [ + 16, 0, 0, 0, 0, 0, 0, 0, 249, 22, 140, 94, 206, 178, 79, 170, 182, 191, + 50, 155, 243, 159, 161, 228, + ]; + b.iter(|| bincode::deserialize::<Uuid>(&bytes).unwrap()); + b.bytes = bytes.len() as u64; +} diff --git a/third_party/rust/uuid/benches/slog_support/mod.rs b/third_party/rust/uuid/benches/slog_support/mod.rs new file mode 100644 index 0000000000..cdc37a7359 --- /dev/null +++ b/third_party/rust/uuid/benches/slog_support/mod.rs @@ -0,0 +1 @@ +pub mod parse_str; diff --git a/third_party/rust/uuid/benches/slog_support/parse_str.rs b/third_party/rust/uuid/benches/slog_support/parse_str.rs new file mode 100644 index 0000000000..fa0e5f7020 --- /dev/null +++ b/third_party/rust/uuid/benches/slog_support/parse_str.rs @@ -0,0 +1,15 @@ +extern crate test; + +#[bench] +#[cfg(feature = "slog")] +pub fn bench_log_discard_kv(b: &mut test::Bencher) { + let u1 = + uuid::Uuid::parse_str("F9168C5E-CEB2-4FAB-B6BF-329BF39FA1E4").unwrap(); + let root = + slog::Logger::root(::slog::Drain::fuse(::slog::Discard), slog::o!()); + + b.iter(|| { + #[cfg(feature = "slog")] + slog::crit!(root, "test"; "u1" => u1); + }); +} diff --git a/third_party/rust/uuid/benches/valid_parse_str.rs b/third_party/rust/uuid/benches/valid_parse_str.rs new file mode 100644 index 0000000000..f20d6e320f --- /dev/null +++ b/third_party/rust/uuid/benches/valid_parse_str.rs @@ -0,0 +1,39 @@ +#![feature(test)] + +extern crate test; + +use test::Bencher; +use uuid::Uuid; + +#[bench] +fn bench_parse_valid_strings(b: &mut Bencher) { + b.iter(|| { + // Valid + let _ = Uuid::parse_str("00000000000000000000000000000000"); + let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8"); + let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8"); + let _ = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4"); + let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8"); + let _ = Uuid::parse_str("01020304-1112-2122-3132-414243444546"); + let _ = + Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8"); + + // Nil + let _ = Uuid::parse_str("00000000000000000000000000000000"); + let _ = Uuid::parse_str("00000000-0000-0000-0000-000000000000"); + }); +} + +#[bench] +fn bench_valid_hyphenated(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8"); + }); +} + +#[bench] +fn bench_valid_short(b: &mut Bencher) { + b.iter(|| { + let _ = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8"); + }); +} |