about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-23 22:46:39 -0700
committerbors <bors@rust-lang.org>2013-07-23 22:46:39 -0700
commit7f96eb58d2a4eed4651570ce719363008a8f269f (patch)
treef674603e356b5ac6d4faa76fdaf5387ecd8cdace /src/libstd/rt
parentaf78e23006d9795bca32267a31e6f3cb9e73a6e1 (diff)
parent978e5d94bc09a18cdfaa699508848bf8a39b46a9 (diff)
downloadrust-7f96eb58d2a4eed4651570ce719363008a8f269f.tar.gz
rust-7f96eb58d2a4eed4651570ce719363008a8f269f.zip
auto merge of #7980 : graydon/rust/misc-benchmarks, r=catamorphism
Some machinery for enabling #[bench] benchmarks in std and some examples showing how to write them.
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/global_heap.rs19
-rw-r--r--src/libstd/rt/local_heap.rs19
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index 580390c1953..54e9cb263db 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -101,3 +101,22 @@ pub unsafe fn exchange_free_(ptr: *c_char) {
 pub unsafe fn exchange_free(ptr: *c_char) {
     free(ptr as *c_void);
 }
+
+#[cfg(test)]
+mod bench {
+    use extra::test::BenchHarness;
+
+    #[bench]
+    fn alloc_owned_small(bh: &mut BenchHarness) {
+        do bh.iter {
+            ~10;
+        }
+    }
+
+    #[bench]
+    fn alloc_owned_big(bh: &mut BenchHarness) {
+        do bh.iter {
+            ~[10, ..1000];
+        }
+    }
+}
diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs
index c909bdb6285..85917ae3edf 100644
--- a/src/libstd/rt/local_heap.rs
+++ b/src/libstd/rt/local_heap.rs
@@ -135,3 +135,22 @@ extern {
     fn rust_boxed_region_free(region: *BoxedRegion, box: *OpaqueBox);
     fn rust_current_boxed_region() -> *BoxedRegion;
 }
+
+#[cfg(test)]
+mod bench {
+    use extra::test::BenchHarness;
+
+    #[bench]
+    fn alloc_managed_small(bh: &mut BenchHarness) {
+        do bh.iter {
+            @10;
+        }
+    }
+
+    #[bench]
+    fn alloc_managed_big(bh: &mut BenchHarness) {
+        do bh.iter {
+            @[10, ..1000];
+        }
+    }
+}