about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-12-31 18:32:19 -0800
committerbors <bors@rust-lang.org>2013-12-31 18:32:19 -0800
commit02cec05c550317f88cd8e3a4574f60ed731fe666 (patch)
tree1dba99f66a24f918b57a5511f7c60f767a11dbbc /src/libstd
parent09a561ac9caaf4acfc170cac92efe6bb5a991a11 (diff)
parent9f1adf07ad3033238d6041c70df1159dd10b8aa3 (diff)
downloadrust-02cec05c550317f88cd8e3a4574f60ed731fe666.tar.gz
rust-02cec05c550317f88cd8e3a4574f60ed731fe666.zip
auto merge of #11137 : g3xzh/rust/benchm, r=cmr
Benchmark testing `is_ancestor_of` and `pop`

ref: https://github.com/mozilla/rust/issues/9694
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/path/posix.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs
index 3f2535765dd..d149634a396 100644
--- a/src/libstd/path/posix.rs
+++ b/src/libstd/path/posix.rs
@@ -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);
+        });
+    }
 }