summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ryu/tests/exhaustive.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/ryu/tests/exhaustive.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/ryu/tests/exhaustive.rs')
-rw-r--r--third_party/rust/ryu/tests/exhaustive.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/third_party/rust/ryu/tests/exhaustive.rs b/third_party/rust/ryu/tests/exhaustive.rs
new file mode 100644
index 0000000000..569bcff921
--- /dev/null
+++ b/third_party/rust/ryu/tests/exhaustive.rs
@@ -0,0 +1,52 @@
+#![cfg(exhaustive)]
+
+use std::str;
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::Arc;
+use std::thread;
+
+#[test]
+fn test_exhaustive() {
+ const BATCH_SIZE: u32 = 1_000_000;
+ let counter = Arc::new(AtomicUsize::new(0));
+ let finished = Arc::new(AtomicUsize::new(0));
+
+ let mut workers = Vec::new();
+ for _ in 0..num_cpus::get() {
+ let counter = counter.clone();
+ let finished = finished.clone();
+ workers.push(thread::spawn(move || loop {
+ let batch = counter.fetch_add(1, Ordering::Relaxed) as u32;
+ if batch > u32::max_value() / BATCH_SIZE {
+ return;
+ }
+
+ let min = batch * BATCH_SIZE;
+ let max = if batch == u32::max_value() / BATCH_SIZE {
+ u32::max_value()
+ } else {
+ min + BATCH_SIZE - 1
+ };
+
+ let mut bytes = [0u8; 24];
+ let mut buffer = ryu::Buffer::new();
+ for u in min..=max {
+ let f = f32::from_bits(u);
+ if !f.is_finite() {
+ continue;
+ }
+ let n = unsafe { ryu::raw::format32(f, &mut bytes[0]) };
+ assert_eq!(Ok(Ok(f)), str::from_utf8(&bytes[..n]).map(str::parse));
+ assert_eq!(Ok(f), buffer.format_finite(f).parse());
+ }
+
+ let increment = (max - min + 1) as usize;
+ let update = finished.fetch_add(increment, Ordering::Relaxed);
+ println!("{}", update + increment);
+ }));
+ }
+
+ for w in workers {
+ w.join().unwrap();
+ }
+}