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;
|
2015-01-14 15:31:17 +08:00
|
|
|
|
|
|
|
static mut ctx_slot: *mut Context = 0 as *mut Context;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
|
|
|
#[bench]
|
2015-01-14 15:31:17 +08:00
|
|
|
fn swap(b: &mut test::Bencher) {
|
|
|
|
unsafe {
|
|
|
|
let mut ctx = Context::new(move |:| {
|
|
|
|
let ctx_ptr = ctx_slot;
|
|
|
|
loop {
|
|
|
|
(*ctx_ptr).swap()
|
|
|
|
}
|
|
|
|
});
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
ctx_slot = &mut ctx;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
ctx.swap();
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
b.iter(|| ctx.swap());
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|