forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135621 - bjorn3:move_tests_to_stdtests, r=Noratrieb Move some std tests to integration tests Unit tests directly inside of standard library crates require a very fragile way of building that is hard to reproduce outside of bootstrap. Follow up to rust-lang#133859
- Loading branch information
Showing
53 changed files
with
635 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
extern crate test; | ||
|
||
mod hash; | ||
mod path; | ||
mod time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use core::hint::black_box; | ||
use std::collections::{BTreeSet, HashSet}; | ||
use std::hash::{DefaultHasher, Hash, Hasher}; | ||
use std::path::*; | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // Miri isn't fast... | ||
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) { | ||
let prefix = "my/home"; | ||
let mut paths: Vec<_> = | ||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect(); | ||
|
||
paths.sort(); | ||
|
||
b.iter(|| { | ||
black_box(paths.as_mut_slice()).sort_unstable(); | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // Miri isn't fast... | ||
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) { | ||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/"; | ||
let paths: Vec<_> = | ||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect(); | ||
|
||
let mut set = BTreeSet::new(); | ||
|
||
paths.iter().for_each(|p| { | ||
set.insert(p.as_path()); | ||
}); | ||
|
||
b.iter(|| { | ||
set.remove(paths[500].as_path()); | ||
set.insert(paths[500].as_path()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // Miri isn't fast... | ||
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) { | ||
let prefix = "my/home"; | ||
let paths: Vec<_> = | ||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect(); | ||
|
||
let mut set = BTreeSet::new(); | ||
|
||
paths.iter().for_each(|p| { | ||
set.insert(p.as_path()); | ||
}); | ||
|
||
b.iter(|| { | ||
set.remove(paths[500].as_path()); | ||
set.insert(paths[500].as_path()); | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // Miri isn't fast... | ||
fn bench_path_hashset(b: &mut test::Bencher) { | ||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/"; | ||
let paths: Vec<_> = | ||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect(); | ||
|
||
let mut set = HashSet::new(); | ||
|
||
paths.iter().for_each(|p| { | ||
set.insert(p.as_path()); | ||
}); | ||
|
||
b.iter(|| { | ||
set.remove(paths[500].as_path()); | ||
set.insert(black_box(paths[500].as_path())) | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[cfg_attr(miri, ignore)] // Miri isn't fast... | ||
fn bench_path_hashset_miss(b: &mut test::Bencher) { | ||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/"; | ||
let paths: Vec<_> = | ||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect(); | ||
|
||
let mut set = HashSet::new(); | ||
|
||
paths.iter().for_each(|p| { | ||
set.insert(p.as_path()); | ||
}); | ||
|
||
let probe = PathBuf::from(prefix).join("other"); | ||
|
||
b.iter(|| set.remove(black_box(probe.as_path()))); | ||
} | ||
|
||
#[bench] | ||
fn bench_hash_path_short(b: &mut test::Bencher) { | ||
let mut hasher = DefaultHasher::new(); | ||
let path = Path::new("explorer.exe"); | ||
|
||
b.iter(|| black_box(path).hash(&mut hasher)); | ||
|
||
black_box(hasher.finish()); | ||
} | ||
|
||
#[bench] | ||
fn bench_hash_path_long(b: &mut test::Bencher) { | ||
let mut hasher = DefaultHasher::new(); | ||
let path = | ||
Path::new("/aaaaa/aaaaaa/./../aaaaaaaa/bbbbbbbbbbbbb/ccccccccccc/ddddddddd/eeeeeee.fff"); | ||
|
||
b.iter(|| black_box(path).hash(&mut hasher)); | ||
|
||
black_box(hasher.finish()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::time::Instant; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
use test::{Bencher, black_box}; | ||
|
||
macro_rules! bench_instant_threaded { | ||
($bench_name:ident, $thread_count:expr) => { | ||
#[bench] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
fn $bench_name(b: &mut Bencher) -> std::thread::Result<()> { | ||
use std::sync::Arc; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
let running = Arc::new(AtomicBool::new(true)); | ||
|
||
let threads: Vec<_> = (0..$thread_count) | ||
.map(|_| { | ||
let flag = Arc::clone(&running); | ||
std::thread::spawn(move || { | ||
while flag.load(Ordering::Relaxed) { | ||
black_box(Instant::now()); | ||
} | ||
}) | ||
}) | ||
.collect(); | ||
|
||
b.iter(|| { | ||
let a = Instant::now(); | ||
let b = Instant::now(); | ||
assert!(b >= a); | ||
}); | ||
|
||
running.store(false, Ordering::Relaxed); | ||
|
||
for t in threads { | ||
t.join()?; | ||
} | ||
Ok(()) | ||
} | ||
}; | ||
} | ||
|
||
bench_instant_threaded!(instant_contention_01_threads, 0); | ||
bench_instant_threaded!(instant_contention_02_threads, 1); | ||
bench_instant_threaded!(instant_contention_04_threads, 3); | ||
bench_instant_threaded!(instant_contention_08_threads, 7); | ||
bench_instant_threaded!(instant_contention_16_threads, 15); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.