Skip to content

Add benchmark tests to path/posix #10691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,3 +1319,89 @@ mod tests {
// the full set of tests
}
}

#[cfg(test)]
mod bench {
use extra::test::BenchHarness;
use super::*;

#[bench]
fn join_home_dir(bh: &mut BenchHarness) {
let posix_path = Path::new("/");
bh.iter(|| {
posix_path.join("home");
});
}

#[bench]
fn join_abs_path_home_dir(bh: &mut BenchHarness) {
let posix_path = Path::new("/");
bh.iter(|| {
posix_path.join("/home");
});
}

#[bench]
fn join_many_home_dir(bh: &mut BenchHarness) {
let posix_path = Path::new("/");
bh.iter(|| {
posix_path.join_many(&["home"]);
});
}

#[bench]
fn join_many_abs_path_home_dir(bh: &mut BenchHarness) {
let posix_path = Path::new("/");
bh.iter(|| {
posix_path.join_many(&["/home"]);
});
}

#[bench]
fn push_home_dir(bh: &mut BenchHarness) {
let mut posix_path = Path::new("/");
bh.iter(|| {
posix_path.push("home");
});
}

#[bench]
fn push_abs_path_home_dir(bh: &mut BenchHarness) {
let mut posix_path = Path::new("/");
bh.iter(|| {
posix_path.push("/home");
});
}

#[bench]
fn push_many_home_dir(bh: &mut BenchHarness) {
let mut posix_path = Path::new("/");
bh.iter(|| {
posix_path.push_many(&["home"]);
});
}

#[bench]
fn push_many_abs_path_home_dir(bh: &mut BenchHarness) {
let mut posix_path = Path::new("/");
bh.iter(|| {
posix_path.push_many(&["/home"]);
});
}

#[bench]
fn ends_with_path_home_dir(bh: &mut BenchHarness) {
let posix_home_path = Path::new("/home");
bh.iter(|| {
posix_home_path.ends_with_path(&Path::new("home"));
});
}

#[bench]
fn ends_with_path_missmatch_jome_home(bh: &mut BenchHarness) {
let posix_home_path = Path::new("/home");
bh.iter(|| {
posix_home_path.ends_with_path(&Path::new("jome"));
});
}
}