Skip to content

Commit

Permalink
auto merge of #11137 : g3xzh/rust/benchm, r=cmr
Browse files Browse the repository at this point in the history
Benchmark testing `is_ancestor_of` and `pop`

ref: #9694
  • Loading branch information
bors committed Jan 1, 2014
2 parents 09a561a + 9f1adf0 commit 02cec05
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,45 @@ mod bench {
posix_home_path.ends_with_path(&Path::new("jome"));
});
}

#[bench]
fn is_ancestor_of_path_with_10_dirs(bh: &mut BenchHarness) {
let path = Path::new("/home/1/2/3/4/5/6/7/8/9");
let mut sub = path.clone();
sub.pop();
bh.iter(|| {
path.is_ancestor_of(&sub);
});
}

#[bench]
fn path_relative_from_forward(bh: &mut BenchHarness) {
let path = Path::new("/a/b/c");
let mut other = path.clone();
other.pop();
bh.iter(|| {
path.path_relative_from(&other);
});
}

#[bench]
fn path_relative_from_same_level(bh: &mut BenchHarness) {
let path = Path::new("/a/b/c");
let mut other = path.clone();
other.pop();
other.push("d");
bh.iter(|| {
path.path_relative_from(&other);
});
}

#[bench]
fn path_relative_from_backward(bh: &mut BenchHarness) {
let path = Path::new("/a/b");
let mut other = path.clone();
other.push("c");
bh.iter(|| {
path.path_relative_from(&other);
});
}
}

0 comments on commit 02cec05

Please sign in to comment.