libfringe/benches/swap.rs

32 lines
757 B
Rust
Raw Normal View History

2015-04-16 20:06:57 +08:00
// This file is part of libfringe, a low-level green threading library.
// Copyright (c) edef <edef@edef.eu>
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)]
#![cfg(feature = "os")]
2014-12-23 11:24:40 +08:00
extern crate test;
2015-04-16 20:06:57 +08:00
extern crate fringe;
use fringe::Context;
2015-04-16 20:06:57 +08:00
static mut ctx_slot: *mut Context<'static, fringe::OsStack> = 0 as *mut Context<_>;
2014-12-23 11:24:40 +08:00
#[bench]
fn swap(b: &mut test::Bencher) {
unsafe {
2015-04-16 20:06:57 +08:00
let stack = fringe::OsStack::new(4 << 20).unwrap();
let mut ctx = Context::new(stack, move || {
let ctx_ptr = ctx_slot;
loop {
Context::swap(ctx_ptr, ctx_ptr);
}
});
2014-12-23 11:24:40 +08:00
let ctx_ptr = &mut ctx;
ctx_slot = ctx_ptr;
2014-12-23 11:24:40 +08:00
Context::swap(ctx_ptr, ctx_ptr);
2014-12-23 11:24:40 +08:00
b.iter(|| Context::swap(ctx_ptr, ctx_ptr));
2014-12-23 11:24:40 +08:00
}
}