Skip to content

Commit 3d5fb47

Browse files
committed
std: add #[bench] benchmarks for global and local heaps.
1 parent e5cbede commit 3d5fb47

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/libstd/rt/global_heap.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,22 @@ pub unsafe fn exchange_free_(ptr: *c_char) {
101101
pub unsafe fn exchange_free(ptr: *c_char) {
102102
free(ptr as *c_void);
103103
}
104+
105+
#[cfg(test)]
106+
mod bench {
107+
use extra::test::BenchHarness;
108+
109+
#[bench]
110+
fn alloc_owned_small(bh: &mut BenchHarness) {
111+
do bh.iter {
112+
~10;
113+
}
114+
}
115+
116+
#[bench]
117+
fn alloc_owned_big(bh: &mut BenchHarness) {
118+
do bh.iter {
119+
~[10, ..1000];
120+
}
121+
}
122+
}

src/libstd/rt/local_heap.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,22 @@ extern {
135135
fn rust_boxed_region_free(region: *BoxedRegion, box: *OpaqueBox);
136136
fn rust_current_boxed_region() -> *BoxedRegion;
137137
}
138+
139+
#[cfg(test)]
140+
mod bench {
141+
use extra::test::BenchHarness;
142+
143+
#[bench]
144+
fn alloc_managed_small(bh: &mut BenchHarness) {
145+
do bh.iter {
146+
@10;
147+
}
148+
}
149+
150+
#[bench]
151+
fn alloc_managed_big(bh: &mut BenchHarness) {
152+
do bh.iter {
153+
@[10, ..1000];
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)