2015-04-16 18:08:44 +08:00
|
|
|
// Copyright (c) 2015, edef <edef@edef.eu>
|
|
|
|
// See the LICENSE file included in this distribution.
|
2015-02-03 03:17:23 +08:00
|
|
|
#![feature(test)]
|
2014-12-23 11:24:40 +08:00
|
|
|
extern crate test;
|
|
|
|
extern crate lwkt;
|
2015-04-16 04:25:09 +08:00
|
|
|
use lwkt::{Context, StackSource};
|
2015-01-14 15:31:17 +08:00
|
|
|
|
2015-04-16 15:53:49 +08:00
|
|
|
static mut ctx_slot: *mut Context<'static, lwkt::os::Stack> = 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 {
|
2015-04-16 16:14:18 +08:00
|
|
|
let stack = lwkt::os::StackSource::get_stack(4 << 20).unwrap();
|
2015-04-16 04:25:09 +08:00
|
|
|
|
|
|
|
let mut ctx = Context::new(stack, move || {
|
2015-01-14 15:31:17 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|