libfringe/benches/swap.rs

25 lines
388 B
Rust
Raw Normal View History

2015-02-03 03:17:23 +08:00
#![feature(test)]
2014-12-23 11:24:40 +08:00
extern crate test;
extern crate lwkt;
use lwkt::Context;
static mut ctx_slot: *mut Context = 0 as *mut Context;
2014-12-23 11:24:40 +08:00
#[bench]
fn swap(b: &mut test::Bencher) {
unsafe {
2015-02-24 12:14:58 +08:00
let mut ctx = Context::new(move || {
let ctx_ptr = ctx_slot;
loop {
(*ctx_ptr).swap()
}
});
2014-12-23 11:24:40 +08:00
ctx_slot = &mut ctx;
2014-12-23 11:24:40 +08:00
ctx.swap();
2014-12-23 11:24:40 +08:00
b.iter(|| ctx.swap());
2014-12-23 11:24:40 +08:00
}
}