Skip to content

Commit

Permalink
std: add #[bench] benchmarks for global and local heaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Jul 22, 2013
1 parent e5cbede commit 3d5fb47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/libstd/rt/global_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
19 changes: 19 additions & 0 deletions src/libstd/rt/local_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}

0 comments on commit 3d5fb47

Please sign in to comment.