libfringe/benches/generator.rs
whitequark 4b32c18f70 Rename Yielder::generate to Yielder::suspend.
This makes more sense, because "generate" implies *running*
a generator, not *returning* from a generator. That name was
a vestige of the time when libfringe only really provided a .next()
implementation, which made marginally more sense together with
.generate(), but it doesn't anymore when we have .resume().
2016-08-30 12:20:34 -04:00

22 lines
793 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 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(|| test::black_box(identity.resume(test::black_box(0))));
}