2015-04-16 03:54:07 +08:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
extern crate lwkt;
|
2015-04-16 04:25:09 +08:00
|
|
|
use lwkt::{Context, StackSource};
|
2015-04-16 03:54:07 +08:00
|
|
|
|
2015-04-16 04:26:51 +08:00
|
|
|
static mut ctx_slot: *mut Context<lwkt::os::Stack> = 0 as *mut Context<_>;
|
2015-04-16 03:54:07 +08:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn context_new(b: &mut test::Bencher) {
|
|
|
|
b.iter(|| unsafe {
|
2015-04-16 04:25:09 +08:00
|
|
|
let stack = lwkt::os::StackSource::get_stack(4 << 20);
|
|
|
|
|
|
|
|
let mut ctx = Context::new(stack, move || {
|
2015-04-16 03:54:07 +08:00
|
|
|
let ctx_ptr = ctx_slot;
|
|
|
|
loop {
|
|
|
|
(*ctx_ptr).swap()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx_slot = &mut ctx;
|
|
|
|
|
|
|
|
ctx.swap();
|
|
|
|
})
|
|
|
|
}
|