Skip to content

Commit ca5ed4c

Browse files
committed
std: add benchmark for allocating-and-dropping a struct with a dtor.
1 parent 9f7e364 commit ca5ed4c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/libstd/ops.rs

+25
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,28 @@ pub trait Shr<RHS,Result> {
8181
pub trait Index<Index,Result> {
8282
fn index(&self, index: &Index) -> Result;
8383
}
84+
85+
#[cfg(test)]
86+
mod bench {
87+
88+
use extra::test::BenchHarness;
89+
use ops::Drop;
90+
91+
// Overhead of dtors
92+
93+
struct HasDtor {
94+
x: int
95+
}
96+
97+
impl Drop for HasDtor {
98+
fn drop(&self) {
99+
}
100+
}
101+
102+
#[bench]
103+
fn alloc_obj_with_dtor(bh: &mut BenchHarness) {
104+
do bh.iter {
105+
HasDtor { x : 10 };
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)