From c19fc4625a651f049fc13c110b6878df9cebdaf1 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 15 Apr 2015 22:01:08 -0400 Subject: [PATCH] use a statically-allocated stack for Context::new benchmarking Now it's an actual context creation benchmark, instead of benchmarking our stack creation, which is swappable anyway. --- benches/context_new.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/benches/context_new.rs b/benches/context_new.rs index 6ac9f51..eb170b9 100644 --- a/benches/context_new.rs +++ b/benches/context_new.rs @@ -1,14 +1,15 @@ #![feature(test)] extern crate test; extern crate lwkt; -use lwkt::{Context, StackSource}; +use lwkt::{Context, Stack}; -static mut ctx_slot: *mut Context = 0 as *mut Context<_>; +static mut ctx_slot: *mut Context> = 0 as *mut Context<_>; +static mut stack_buf: [u8; 1024] = [0; 1024]; #[bench] fn context_new(b: &mut test::Bencher) { b.iter(|| unsafe { - let stack = lwkt::os::StackSource::get_stack(4 << 20); + let stack = SliceStack(&mut stack_buf); let mut ctx = Context::new(stack, move || { let ctx_ptr = ctx_slot; @@ -22,3 +23,16 @@ fn context_new(b: &mut test::Bencher) { ctx.swap(); }) } + +struct SliceStack<'a>(&'a mut [u8]); +impl<'a> lwkt::Stack for SliceStack<'a> { + fn top(&mut self) -> *mut u8 { + unsafe { + self.0.as_mut_ptr().offset(self.0.len() as isize) + } + } + + fn limit(&self) -> *const u8 { + self.0.as_ptr() + } +}