2015-04-16 20:06:57 +08:00
|
|
|
// This file is part of libfringe, a low-level green threading library.
|
2016-07-16 09:22:41 +08:00
|
|
|
// Copyright (c) edef <edef@edef.eu>,
|
|
|
|
// whitequark <whitequark@whitequark.org>
|
2015-04-16 18:08:44 +08:00
|
|
|
// 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;
|
2015-04-16 20:06:57 +08:00
|
|
|
extern crate fringe;
|
2016-07-16 09:22:41 +08:00
|
|
|
|
2015-04-16 20:06:57 +08:00
|
|
|
use fringe::Context;
|
2015-01-14 15:31:17 +08:00
|
|
|
|
2016-07-16 09:22:41 +08:00
|
|
|
static mut ctx_slot: *mut Context<fringe::OsStack> = 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) {
|
2016-07-16 09:22:41 +08:00
|
|
|
unsafe extern "C" fn loopback(mut arg: usize) -> ! {
|
|
|
|
// This deliberately does not ignore arg, to measure the time it takes
|
|
|
|
// to move the return value between registers.
|
|
|
|
let ctx_ptr = ctx_slot;
|
|
|
|
loop { arg = Context::swap(ctx_ptr, ctx_ptr, arg) }
|
|
|
|
}
|
|
|
|
|
2015-01-14 15:31:17 +08:00
|
|
|
unsafe {
|
2015-04-16 20:06:57 +08:00
|
|
|
let stack = fringe::OsStack::new(4 << 20).unwrap();
|
2016-07-16 09:22:41 +08:00
|
|
|
let mut ctx = Context::new(stack, loopback);
|
|
|
|
ctx_slot = &mut ctx;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
2016-04-04 01:54:40 +08:00
|
|
|
let ctx_ptr = &mut ctx;
|
2016-07-16 09:22:41 +08:00
|
|
|
b.iter(|| Context::swap(ctx_ptr, ctx_ptr, 0));
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
}
|