Skip to content

Commit 8760d55

Browse files
committed
benchmark path.components() iteration
1 parent 2aaa62b commit 8760d55

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/std/benches/path.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
5555
});
5656
}
5757

58+
#[bench]
59+
fn bench_path_components_iter(b: &mut test::Bencher) {
60+
let p = Path::new("/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/");
61+
62+
b.iter(|| {
63+
for c in black_box(p).components() {
64+
black_box(c);
65+
}
66+
})
67+
}
68+
69+
#[bench]
70+
fn bench_path_file_name(b: &mut test::Bencher) {
71+
let p1 = Path::new("foo.bar");
72+
let p2 = Path::new("foo/bar");
73+
let p3 = Path::new("/bar");
74+
75+
b.iter(|| {
76+
black_box(black_box(p1).file_name());
77+
black_box(black_box(p2).file_name());
78+
black_box(black_box(p3).file_name());
79+
})
80+
}
81+
5882
#[bench]
5983
#[cfg_attr(miri, ignore)] // Miri isn't fast...
6084
fn bench_path_hashset(b: &mut test::Bencher) {

0 commit comments

Comments
 (0)