2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.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.
|
|
|
|
|
2014-07-26 21:05:03 -07:00
|
|
|
#![feature(unsafe_destructor)]
|
2013-10-23 04:49:18 -04:00
|
|
|
|
2013-05-24 19:35:29 -07:00
|
|
|
use std::os;
|
|
|
|
use std::task;
|
2014-11-10 12:27:56 -08:00
|
|
|
use std::time::Duration;
|
2012-06-02 17:42:48 -07:00
|
|
|
|
2014-12-31 17:32:49 +13:00
|
|
|
#[derive(Clone)]
|
2014-03-18 21:31:40 -07:00
|
|
|
enum List<T> {
|
2014-10-02 08:10:09 +03:00
|
|
|
Nil, Cons(T, Box<List<T>>)
|
2014-03-18 21:31:40 -07:00
|
|
|
}
|
|
|
|
|
2013-01-31 17:12:29 -08:00
|
|
|
enum UniqueList {
|
2014-05-05 18:56:44 -07:00
|
|
|
ULNil, ULCons(Box<UniqueList>)
|
2013-01-31 17:12:29 -08:00
|
|
|
}
|
|
|
|
|
2012-06-02 17:42:48 -07:00
|
|
|
fn main() {
|
2013-07-17 15:31:20 -04:00
|
|
|
let (repeat, depth) = if os::getenv("RUST_BENCH").is_some() {
|
2012-06-02 17:42:48 -07:00
|
|
|
(50, 1000)
|
|
|
|
} else {
|
|
|
|
(10, 10)
|
|
|
|
};
|
|
|
|
|
|
|
|
run(repeat, depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(repeat: int, depth: int) {
|
2013-08-05 23:43:06 -04:00
|
|
|
for _ in range(0, repeat) {
|
2014-11-10 12:27:56 -08:00
|
|
|
let dur = Duration::span(|| {
|
2014-11-26 08:12:18 -05:00
|
|
|
task::try(move|| {
|
2014-11-10 12:27:56 -08:00
|
|
|
recurse_or_panic(depth, None)
|
|
|
|
});
|
2014-01-27 18:29:50 -05:00
|
|
|
});
|
2014-11-10 12:27:56 -08:00
|
|
|
println!("iter: {}", dur);
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:12:14 -07:00
|
|
|
type nillist = List<()>;
|
2012-06-02 17:42:48 -07:00
|
|
|
|
|
|
|
// Filled with things that have to be unwound
|
2013-01-28 18:55:44 -08:00
|
|
|
|
|
|
|
struct State {
|
2014-05-05 18:56:44 -07:00
|
|
|
unique: Box<nillist>,
|
2014-10-02 08:10:09 +03:00
|
|
|
vec: Vec<Box<nillist>>,
|
2013-01-28 18:55:44 -08:00
|
|
|
res: r
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 18:46:55 -07:00
|
|
|
struct r {
|
2014-10-02 08:10:09 +03:00
|
|
|
_l: Box<nillist>,
|
2012-11-14 01:22:37 -05:00
|
|
|
}
|
|
|
|
|
2013-03-20 18:18:57 -07:00
|
|
|
#[unsafe_destructor]
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Drop for r {
|
2013-09-16 21:18:07 -04:00
|
|
|
fn drop(&mut self) {}
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
|
2014-10-02 08:10:09 +03:00
|
|
|
fn r(l: Box<nillist>) -> r {
|
2012-09-05 15:58:43 -07:00
|
|
|
r {
|
|
|
|
_l: l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:17:22 -04:00
|
|
|
fn recurse_or_panic(depth: int, st: Option<State>) {
|
2012-06-02 17:42:48 -07:00
|
|
|
if depth == 0 {
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!();
|
2012-06-02 17:42:48 -07:00
|
|
|
} else {
|
|
|
|
let depth = depth - 1;
|
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
let st = match st {
|
2014-10-14 23:05:01 -07:00
|
|
|
None => {
|
|
|
|
State {
|
2014-11-06 00:05:53 -08:00
|
|
|
unique: box List::Nil,
|
|
|
|
vec: vec!(box List::Nil),
|
|
|
|
res: r(box List::Nil)
|
2014-10-14 23:05:01 -07:00
|
|
|
}
|
2013-01-28 18:55:44 -08:00
|
|
|
}
|
2014-10-14 23:05:01 -07:00
|
|
|
Some(st) => {
|
|
|
|
let mut v = st.vec.clone();
|
2014-11-06 00:05:53 -08:00
|
|
|
v.push_all(&[box List::Cons((), st.vec.last().unwrap().clone())]);
|
2014-10-14 23:05:01 -07:00
|
|
|
State {
|
2014-11-06 00:05:53 -08:00
|
|
|
unique: box List::Cons((), box *st.unique),
|
2014-10-14 23:05:01 -07:00
|
|
|
vec: v,
|
2014-11-06 00:05:53 -08:00
|
|
|
res: r(box List::Cons((), st.res._l.clone())),
|
2014-10-14 23:05:01 -07:00
|
|
|
}
|
2013-01-28 18:55:44 -08:00
|
|
|
}
|
2012-06-02 17:42:48 -07:00
|
|
|
};
|
|
|
|
|
2014-10-09 15:17:22 -04:00
|
|
|
recurse_or_panic(depth, Some(st));
|
2012-06-02 17:42:48 -07:00
|
|
|
}
|
|
|
|
}
|