]> git.lizzy.rs Git - rust.git/commitdiff
std: add benchmark for allocating-and-dropping a struct with a dtor.
authorGraydon Hoare <graydon@mozilla.com>
Mon, 22 Jul 2013 23:50:17 +0000 (16:50 -0700)
committerGraydon Hoare <graydon@mozilla.com>
Mon, 22 Jul 2013 23:56:11 +0000 (16:56 -0700)
src/libstd/ops.rs

index 020131ab119e5080f2407d0851548c8f67e4b99b..756b4a10d3c9042ed7aa576b50edad859e515fce 100644 (file)
@@ -81,3 +81,28 @@ pub trait Shr<RHS,Result> {
 pub trait Index<Index,Result> {
     fn index(&self, index: &Index) -> Result;
 }
+
+#[cfg(test)]
+mod bench {
+
+    use extra::test::BenchHarness;
+    use ops::Drop;
+
+    // Overhead of dtors
+
+    struct HasDtor {
+        x: int
+    }
+
+    impl Drop for HasDtor {
+        fn drop(&self) {
+        }
+    }
+
+    #[bench]
+    fn alloc_obj_with_dtor(bh: &mut BenchHarness) {
+        do bh.iter {
+            HasDtor { x : 10 };
+        }
+    }
+}
\ No newline at end of file