Skip to content

Commit

Permalink
Add benchmark tests to path/posix
Browse files Browse the repository at this point in the history
I have written some benchmark tests to `push`, `push_many`, `join`,
`join_many` and `ends_with_path`.
  • Loading branch information
g3xzh committed Nov 27, 2013
1 parent 82d9033 commit 26ba64d
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/libstd/path/posix.rs
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"));
});
}
}

5 comments on commit 26ba64d

@bors
Copy link
Contributor

@bors bors commented on 26ba64d Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at g3xzh@26ba64d

@bors
Copy link
Contributor

@bors bors commented on 26ba64d Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging g3xzh/rust/benchm = 26ba64d into auto

@bors
Copy link
Contributor

@bors bors commented on 26ba64d Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g3xzh/rust/benchm = 26ba64d merged ok, testing candidate = 68e3292

@bors
Copy link
Contributor

@bors bors commented on 26ba64d Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 26ba64d Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 68e3292

Please sign in to comment.