Skip to content

Commit 02cec05

Browse files
committed
auto merge of #11137 : g3xzh/rust/benchm, r=cmr
Benchmark testing `is_ancestor_of` and `pop` ref: #9694
2 parents 09a561a + 9f1adf0 commit 02cec05

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/libstd/path/posix.rs

+41
Original file line numberDiff line numberDiff line change
@@ -1404,4 +1404,45 @@ mod bench {
14041404
posix_home_path.ends_with_path(&Path::new("jome"));
14051405
});
14061406
}
1407+
1408+
#[bench]
1409+
fn is_ancestor_of_path_with_10_dirs(bh: &mut BenchHarness) {
1410+
let path = Path::new("/home/1/2/3/4/5/6/7/8/9");
1411+
let mut sub = path.clone();
1412+
sub.pop();
1413+
bh.iter(|| {
1414+
path.is_ancestor_of(&sub);
1415+
});
1416+
}
1417+
1418+
#[bench]
1419+
fn path_relative_from_forward(bh: &mut BenchHarness) {
1420+
let path = Path::new("/a/b/c");
1421+
let mut other = path.clone();
1422+
other.pop();
1423+
bh.iter(|| {
1424+
path.path_relative_from(&other);
1425+
});
1426+
}
1427+
1428+
#[bench]
1429+
fn path_relative_from_same_level(bh: &mut BenchHarness) {
1430+
let path = Path::new("/a/b/c");
1431+
let mut other = path.clone();
1432+
other.pop();
1433+
other.push("d");
1434+
bh.iter(|| {
1435+
path.path_relative_from(&other);
1436+
});
1437+
}
1438+
1439+
#[bench]
1440+
fn path_relative_from_backward(bh: &mut BenchHarness) {
1441+
let path = Path::new("/a/b");
1442+
let mut other = path.clone();
1443+
other.push("c");
1444+
bh.iter(|| {
1445+
path.path_relative_from(&other);
1446+
});
1447+
}
14071448
}

0 commit comments

Comments
 (0)