libfringe/benches/generator.rs

24 lines
852 B
Rust

// This file is part of libfringe, a low-level green threading library.
// Copyright (c) whitequark <whitequark@whitequark.org>
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
#![feature(test)]
extern crate test;
extern crate fringe;
use std::mem;
use fringe::{OsStack, Generator};
#[bench]
fn generate(b: &mut test::Bencher) {
let stack = OsStack::new(0).unwrap();
let mut identity = Generator::new(stack, move |yielder, mut input| {
loop { input = yielder.suspend(input) }
});
b.iter(|| for _ in 0..10 { test::black_box(identity.resume(test::black_box(0))); });
mem::forget(identity);
}