diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/once_cell/examples | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/once_cell/examples')
-rw-r--r-- | vendor/once_cell/examples/bench_vs_lazy_static.rs | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/vendor/once_cell/examples/bench_vs_lazy_static.rs b/vendor/once_cell/examples/bench_vs_lazy_static.rs deleted file mode 100644 index c23b0124e..000000000 --- a/vendor/once_cell/examples/bench_vs_lazy_static.rs +++ /dev/null @@ -1,51 +0,0 @@ -use lazy_static::lazy_static; -use once_cell::sync::Lazy; - -const N_THREADS: usize = 32; -const N_ROUNDS: usize = 100_000_000; - -static ONCE_CELL: Lazy<Vec<String>> = Lazy::new(|| vec!["Spica".to_string(), "Hoyten".to_string()]); - -lazy_static! { - static ref LAZY_STATIC: Vec<String> = vec!["Spica".to_string(), "Hoyten".to_string()]; -} - -fn main() { - let once_cell = { - let start = std::time::Instant::now(); - let threads = (0..N_THREADS) - .map(|_| std::thread::spawn(move || thread_once_cell())) - .collect::<Vec<_>>(); - for thread in threads { - thread.join().unwrap(); - } - start.elapsed() - }; - let lazy_static = { - let start = std::time::Instant::now(); - let threads = (0..N_THREADS) - .map(|_| std::thread::spawn(move || thread_lazy_static())) - .collect::<Vec<_>>(); - for thread in threads { - thread.join().unwrap(); - } - start.elapsed() - }; - - println!("once_cell: {:?}", once_cell); - println!("lazy_static: {:?}", lazy_static); -} - -fn thread_once_cell() { - for _ in 0..N_ROUNDS { - let len = ONCE_CELL.len(); - assert_eq!(len, 2) - } -} - -fn thread_lazy_static() { - for _ in 0..N_ROUNDS { - let len = LAZY_STATIC.len(); - assert_eq!(len, 2) - } -} |