testsuite: De-record most bench tests
This commit is contained in:
parent
3b36708ca7
commit
fc9650b146
5 changed files with 78 additions and 62 deletions
|
@ -27,7 +27,10 @@ fn print_complements() {
|
||||||
|
|
||||||
enum color { Red, Yellow, Blue }
|
enum color { Red, Yellow, Blue }
|
||||||
|
|
||||||
type creature_info = { name: uint, color: color };
|
struct CreatureInfo {
|
||||||
|
name: uint,
|
||||||
|
color: color
|
||||||
|
}
|
||||||
|
|
||||||
fn show_color(cc: color) -> ~str {
|
fn show_color(cc: color) -> ~str {
|
||||||
match (cc) {
|
match (cc) {
|
||||||
|
@ -95,8 +98,8 @@ fn transform(aa: color, bb: color) -> color {
|
||||||
fn creature(
|
fn creature(
|
||||||
name: uint,
|
name: uint,
|
||||||
color: color,
|
color: color,
|
||||||
from_rendezvous: oldcomm::Port<Option<creature_info>>,
|
from_rendezvous: oldcomm::Port<Option<CreatureInfo>>,
|
||||||
to_rendezvous: oldcomm::Chan<creature_info>,
|
to_rendezvous: oldcomm::Chan<CreatureInfo>,
|
||||||
to_rendezvous_log: oldcomm::Chan<~str>
|
to_rendezvous_log: oldcomm::Chan<~str>
|
||||||
) {
|
) {
|
||||||
let mut color = color;
|
let mut color = color;
|
||||||
|
@ -105,7 +108,7 @@ fn creature(
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// ask for a pairing
|
// ask for a pairing
|
||||||
oldcomm::send(to_rendezvous, {name: name, color: color});
|
oldcomm::send(to_rendezvous, CreatureInfo {name: name, color: color});
|
||||||
let resp = oldcomm::recv(from_rendezvous);
|
let resp = oldcomm::recv(from_rendezvous);
|
||||||
|
|
||||||
// log and change, or print and quit
|
// log and change, or print and quit
|
||||||
|
@ -145,7 +148,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// these ports will allow us to hear from the creatures
|
// these ports will allow us to hear from the creatures
|
||||||
let from_creatures: oldcomm::Port<creature_info> = oldcomm::Port();
|
let from_creatures: oldcomm::Port<CreatureInfo> = oldcomm::Port();
|
||||||
let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port();
|
let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port();
|
||||||
|
|
||||||
// these channels will be passed to the creatures so they can talk to us
|
// these channels will be passed to the creatures so they can talk to us
|
||||||
|
@ -153,7 +156,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
||||||
let to_rendezvous_log = oldcomm::Chan(&from_creatures_log);
|
let to_rendezvous_log = oldcomm::Chan(&from_creatures_log);
|
||||||
|
|
||||||
// these channels will allow us to talk to each creature by 'name'/index
|
// these channels will allow us to talk to each creature by 'name'/index
|
||||||
let to_creature: ~[oldcomm::Chan<Option<creature_info>>] =
|
let to_creature: ~[oldcomm::Chan<Option<CreatureInfo>>] =
|
||||||
vec::mapi(set, |ii, col| {
|
vec::mapi(set, |ii, col| {
|
||||||
// create each creature as a listener with a port, and
|
// create each creature as a listener with a port, and
|
||||||
// give us a channel to talk to each
|
// give us a channel to talk to each
|
||||||
|
@ -169,8 +172,8 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
||||||
|
|
||||||
// set up meetings...
|
// set up meetings...
|
||||||
for nn.times {
|
for nn.times {
|
||||||
let fst_creature: creature_info = oldcomm::recv(from_creatures);
|
let fst_creature: CreatureInfo = oldcomm::recv(from_creatures);
|
||||||
let snd_creature: creature_info = oldcomm::recv(from_creatures);
|
let snd_creature: CreatureInfo = oldcomm::recv(from_creatures);
|
||||||
|
|
||||||
creatures_met += 2;
|
creatures_met += 2;
|
||||||
|
|
||||||
|
|
|
@ -20,25 +20,33 @@ use io::WriterUtil;
|
||||||
|
|
||||||
fn LINE_LENGTH() -> uint { return 60u; }
|
fn LINE_LENGTH() -> uint { return 60u; }
|
||||||
|
|
||||||
type myrandom = @{mut last: u32};
|
struct MyRandom {
|
||||||
|
mut last: u32
|
||||||
|
}
|
||||||
|
|
||||||
fn myrandom_next(r: myrandom, mx: u32) -> u32 {
|
fn myrandom_next(r: @MyRandom, mx: u32) -> u32 {
|
||||||
r.last = (r.last * 3877u32 + 29573u32) % 139968u32;
|
r.last = (r.last * 3877u32 + 29573u32) % 139968u32;
|
||||||
mx * r.last / 139968u32
|
mx * r.last / 139968u32
|
||||||
}
|
}
|
||||||
|
|
||||||
type aminoacids = {ch: char, prob: u32};
|
struct AminoAcids {
|
||||||
|
ch: char,
|
||||||
|
prob: u32
|
||||||
|
}
|
||||||
|
|
||||||
fn make_cumulative(aa: ~[aminoacids]) -> ~[aminoacids] {
|
fn make_cumulative(aa: ~[AminoAcids]) -> ~[AminoAcids] {
|
||||||
let mut cp: u32 = 0u32;
|
let mut cp: u32 = 0u32;
|
||||||
let mut ans: ~[aminoacids] = ~[];
|
let mut ans: ~[AminoAcids] = ~[];
|
||||||
for aa.each |a| { cp += a.prob; ans += ~[{ch: a.ch, prob: cp}]; }
|
for aa.each |a| {
|
||||||
|
cp += a.prob;
|
||||||
|
ans += ~[AminoAcids {ch: a.ch, prob: cp}];
|
||||||
|
}
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_random(r: u32, genelist: ~[aminoacids]) -> char {
|
fn select_random(r: u32, genelist: ~[AminoAcids]) -> char {
|
||||||
if r < genelist[0].prob { return genelist[0].ch; }
|
if r < genelist[0].prob { return genelist[0].ch; }
|
||||||
fn bisect(v: ~[aminoacids], lo: uint, hi: uint, target: u32) -> char {
|
fn bisect(v: ~[AminoAcids], lo: uint, hi: uint, target: u32) -> char {
|
||||||
if hi > lo + 1u {
|
if hi > lo + 1u {
|
||||||
let mid: uint = lo + (hi - lo) / 2u;
|
let mid: uint = lo + (hi - lo) / 2u;
|
||||||
if target < v[mid].prob {
|
if target < v[mid].prob {
|
||||||
|
@ -46,12 +54,12 @@ fn select_random(r: u32, genelist: ~[aminoacids]) -> char {
|
||||||
} else { return bisect(v, mid, hi, target); }
|
} else { return bisect(v, mid, hi, target); }
|
||||||
} else { return v[hi].ch; }
|
} else { return v[hi].ch; }
|
||||||
}
|
}
|
||||||
return bisect(copy genelist, 0, vec::len::<aminoacids>(genelist) - 1, r);
|
return bisect(copy genelist, 0, vec::len::<AminoAcids>(genelist) - 1, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[aminoacids], n: int) {
|
fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[AminoAcids], n: int) {
|
||||||
wr.write_line(~">" + id + ~" " + desc);
|
wr.write_line(~">" + id + ~" " + desc);
|
||||||
let rng = @{mut last: rand::Rng().next()};
|
let rng = @MyRandom {mut last: rand::Rng().next()};
|
||||||
let mut op: ~str = ~"";
|
let mut op: ~str = ~"";
|
||||||
for uint::range(0u, n as uint) |_i| {
|
for uint::range(0u, n as uint) |_i| {
|
||||||
str::push_char(&mut op, select_random(myrandom_next(rng, 100u32),
|
str::push_char(&mut op, select_random(myrandom_next(rng, 100u32),
|
||||||
|
@ -80,7 +88,9 @@ fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn acid(ch: char, prob: u32) -> aminoacids { return {ch: ch, prob: prob}; }
|
fn acid(ch: char, prob: u32) -> AminoAcids {
|
||||||
|
return AminoAcids {ch: ch, prob: prob};
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
|
@ -102,13 +112,13 @@ fn main() {
|
||||||
|
|
||||||
let n = int::from_str(args[1]).get();
|
let n = int::from_str(args[1]).get();
|
||||||
|
|
||||||
let iub: ~[aminoacids] =
|
let iub: ~[AminoAcids] =
|
||||||
make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
|
make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
|
||||||
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
|
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
|
||||||
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
|
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
|
||||||
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
|
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
|
||||||
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
|
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
|
||||||
let homosapiens: ~[aminoacids] =
|
let homosapiens: ~[AminoAcids] =
|
||||||
make_cumulative(~[acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
|
make_cumulative(~[acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
|
||||||
acid('t', 30u32)]);
|
acid('t', 30u32)]);
|
||||||
let alu: ~str =
|
let alu: ~str =
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn main() {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
let n = int::from_str(args[1]).get();
|
let n = int::from_str(args[1]).get();
|
||||||
let mut bodies: ~[Body::props] = NBodySystem::make();
|
let mut bodies: ~[Body::Props] = NBodySystem::make();
|
||||||
io::println(fmt!("%f", NBodySystem::energy(bodies)));
|
io::println(fmt!("%f", NBodySystem::energy(bodies)));
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < n {
|
while i < n {
|
||||||
|
@ -49,8 +49,8 @@ fn main() {
|
||||||
mod NBodySystem {
|
mod NBodySystem {
|
||||||
use Body;
|
use Body;
|
||||||
|
|
||||||
pub fn make() -> ~[Body::props] {
|
pub fn make() -> ~[Body::Props] {
|
||||||
let mut bodies: ~[Body::props] =
|
let mut bodies: ~[Body::Props] =
|
||||||
~[Body::sun(),
|
~[Body::sun(),
|
||||||
Body::jupiter(),
|
Body::jupiter(),
|
||||||
Body::saturn(),
|
Body::saturn(),
|
||||||
|
@ -76,7 +76,7 @@ mod NBodySystem {
|
||||||
return bodies;
|
return bodies;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance(bodies: &mut [Body::props], dt: float) {
|
pub fn advance(bodies: &mut [Body::Props], dt: float) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < 5 {
|
while i < 5 {
|
||||||
let mut j = i + 1;
|
let mut j = i + 1;
|
||||||
|
@ -96,8 +96,8 @@ mod NBodySystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance_one(bi: &mut Body::props,
|
pub fn advance_one(bi: &mut Body::Props,
|
||||||
bj: &mut Body::props,
|
bj: &mut Body::Props,
|
||||||
dt: float) {
|
dt: float) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let dx = bi.x - bj.x;
|
let dx = bi.x - bj.x;
|
||||||
|
@ -119,13 +119,13 @@ mod NBodySystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_(b: &mut Body::props, dt: float) {
|
pub fn move_(b: &mut Body::Props, dt: float) {
|
||||||
b.x += dt * b.vx;
|
b.x += dt * b.vx;
|
||||||
b.y += dt * b.vy;
|
b.y += dt * b.vy;
|
||||||
b.z += dt * b.vz;
|
b.z += dt * b.vz;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn energy(bodies: &[Body::props]) -> float {
|
pub fn energy(bodies: &[Body::Props]) -> float {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut dx;
|
let mut dx;
|
||||||
let mut dy;
|
let mut dy;
|
||||||
|
@ -171,17 +171,17 @@ mod Body {
|
||||||
// was 4 * PI * PI originally
|
// was 4 * PI * PI originally
|
||||||
pub const DAYS_PER_YEAR: float = 365.24;
|
pub const DAYS_PER_YEAR: float = 365.24;
|
||||||
|
|
||||||
pub type props =
|
pub struct Props
|
||||||
{mut x: float,
|
{mut x: float,
|
||||||
mut y: float,
|
mut y: float,
|
||||||
mut z: float,
|
mut z: float,
|
||||||
mut vx: float,
|
mut vx: float,
|
||||||
mut vy: float,
|
mut vy: float,
|
||||||
mut vz: float,
|
mut vz: float,
|
||||||
mass: float};
|
mass: float}
|
||||||
|
|
||||||
pub fn jupiter() -> Body::props {
|
pub fn jupiter() -> Body::Props {
|
||||||
return {mut x: 4.84143144246472090e+00,
|
return Props {mut x: 4.84143144246472090e+00,
|
||||||
mut y: -1.16032004402742839e+00,
|
mut y: -1.16032004402742839e+00,
|
||||||
mut z: -1.03622044471123109e-01,
|
mut z: -1.03622044471123109e-01,
|
||||||
mut vx: 1.66007664274403694e-03 * DAYS_PER_YEAR,
|
mut vx: 1.66007664274403694e-03 * DAYS_PER_YEAR,
|
||||||
|
@ -190,8 +190,8 @@ mod Body {
|
||||||
mass: 9.54791938424326609e-04 * SOLAR_MASS};
|
mass: 9.54791938424326609e-04 * SOLAR_MASS};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saturn() -> Body::props {
|
pub fn saturn() -> Body::Props {
|
||||||
return {mut x: 8.34336671824457987e+00,
|
return Props {mut x: 8.34336671824457987e+00,
|
||||||
mut y: 4.12479856412430479e+00,
|
mut y: 4.12479856412430479e+00,
|
||||||
mut z: -4.03523417114321381e-01,
|
mut z: -4.03523417114321381e-01,
|
||||||
mut vx: -2.76742510726862411e-03 * DAYS_PER_YEAR,
|
mut vx: -2.76742510726862411e-03 * DAYS_PER_YEAR,
|
||||||
|
@ -200,8 +200,8 @@ mod Body {
|
||||||
mass: 2.85885980666130812e-04 * SOLAR_MASS};
|
mass: 2.85885980666130812e-04 * SOLAR_MASS};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uranus() -> Body::props {
|
pub fn uranus() -> Body::Props {
|
||||||
return {mut x: 1.28943695621391310e+01,
|
return Props {mut x: 1.28943695621391310e+01,
|
||||||
mut y: -1.51111514016986312e+01,
|
mut y: -1.51111514016986312e+01,
|
||||||
mut z: -2.23307578892655734e-01,
|
mut z: -2.23307578892655734e-01,
|
||||||
mut vx: 2.96460137564761618e-03 * DAYS_PER_YEAR,
|
mut vx: 2.96460137564761618e-03 * DAYS_PER_YEAR,
|
||||||
|
@ -210,8 +210,8 @@ mod Body {
|
||||||
mass: 4.36624404335156298e-05 * SOLAR_MASS};
|
mass: 4.36624404335156298e-05 * SOLAR_MASS};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn neptune() -> Body::props {
|
pub fn neptune() -> Body::Props {
|
||||||
return {mut x: 1.53796971148509165e+01,
|
return Props {mut x: 1.53796971148509165e+01,
|
||||||
mut y: -2.59193146099879641e+01,
|
mut y: -2.59193146099879641e+01,
|
||||||
mut z: 1.79258772950371181e-01,
|
mut z: 1.79258772950371181e-01,
|
||||||
mut vx: 2.68067772490389322e-03 * DAYS_PER_YEAR,
|
mut vx: 2.68067772490389322e-03 * DAYS_PER_YEAR,
|
||||||
|
@ -220,8 +220,8 @@ mod Body {
|
||||||
mass: 5.15138902046611451e-05 * SOLAR_MASS};
|
mass: 5.15138902046611451e-05 * SOLAR_MASS};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sun() -> Body::props {
|
pub fn sun() -> Body::Props {
|
||||||
return {mut x: 0.0,
|
return Props {mut x: 0.0,
|
||||||
mut y: 0.0,
|
mut y: 0.0,
|
||||||
mut z: 0.0,
|
mut z: 0.0,
|
||||||
mut vx: 0.0,
|
mut vx: 0.0,
|
||||||
|
@ -230,7 +230,7 @@ mod Body {
|
||||||
mass: SOLAR_MASS};
|
mass: SOLAR_MASS};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset_momentum(props: &mut Body::props,
|
pub fn offset_momentum(props: &mut Body::Props,
|
||||||
px: float, py: float, pz: float) {
|
px: float, py: float, pz: float) {
|
||||||
props.vx = -px / SOLAR_MASS;
|
props.vx = -px / SOLAR_MASS;
|
||||||
props.vy = -py / SOLAR_MASS;
|
props.vy = -py / SOLAR_MASS;
|
||||||
|
|
|
@ -55,15 +55,19 @@ fn fib(n: int) -> int {
|
||||||
p.recv()
|
p.recv()
|
||||||
}
|
}
|
||||||
|
|
||||||
type config = {stress: bool};
|
struct Config {
|
||||||
|
stress: bool
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_opts(argv: ~[~str]) -> config {
|
fn parse_opts(argv: ~[~str]) -> Config {
|
||||||
let opts = ~[getopts::optflag(~"stress")];
|
let opts = ~[getopts::optflag(~"stress")];
|
||||||
|
|
||||||
let opt_args = vec::slice(argv, 1u, vec::len(argv));
|
let opt_args = vec::slice(argv, 1, argv.len());
|
||||||
|
|
||||||
match getopts::getopts(opt_args, opts) {
|
match getopts::getopts(opt_args, opts) {
|
||||||
Ok(ref m) => { return {stress: getopts::opt_present(m, ~"stress")} }
|
Ok(ref m) => {
|
||||||
|
return Config {stress: getopts::opt_present(m, ~"stress")}
|
||||||
|
}
|
||||||
Err(_) => { fail; }
|
Err(_) => { fail; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,16 +38,15 @@ fn run(repeat: int, depth: int) {
|
||||||
type nillist = List<()>;
|
type nillist = List<()>;
|
||||||
|
|
||||||
// Filled with things that have to be unwound
|
// Filled with things that have to be unwound
|
||||||
enum st {
|
|
||||||
st_({
|
struct State {
|
||||||
box: @nillist,
|
box: @nillist,
|
||||||
unique: ~nillist,
|
unique: ~nillist,
|
||||||
fn_box: fn@() -> @nillist,
|
fn_box: fn@() -> @nillist,
|
||||||
fn_unique: fn~() -> ~nillist,
|
fn_unique: fn~() -> ~nillist,
|
||||||
tuple: (@nillist, ~nillist),
|
tuple: (@nillist, ~nillist),
|
||||||
vec: ~[@nillist],
|
vec: ~[@nillist],
|
||||||
res: r
|
res: r
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
|
@ -64,7 +63,7 @@ fn r(l: @nillist) -> r {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recurse_or_fail(depth: int, st: Option<st>) {
|
fn recurse_or_fail(depth: int, st: Option<State>) {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
debug!("unwinding %.4f", precise_time_s());
|
debug!("unwinding %.4f", precise_time_s());
|
||||||
fail;
|
fail;
|
||||||
|
@ -73,7 +72,7 @@ fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||||
|
|
||||||
let st = match st {
|
let st = match st {
|
||||||
None => {
|
None => {
|
||||||
st_({
|
State {
|
||||||
box: @Nil,
|
box: @Nil,
|
||||||
unique: ~Nil,
|
unique: ~Nil,
|
||||||
fn_box: fn@() -> @nillist { @Nil::<()> },
|
fn_box: fn@() -> @nillist { @Nil::<()> },
|
||||||
|
@ -81,13 +80,13 @@ fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||||
tuple: (@Nil, ~Nil),
|
tuple: (@Nil, ~Nil),
|
||||||
vec: ~[@Nil],
|
vec: ~[@Nil],
|
||||||
res: r(@Nil)
|
res: r(@Nil)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
Some(st) => {
|
Some(st) => {
|
||||||
let fn_box = st.fn_box;
|
let fn_box = st.fn_box;
|
||||||
let fn_unique = copy st.fn_unique;
|
let fn_unique = copy st.fn_unique;
|
||||||
|
|
||||||
st_({
|
State {
|
||||||
box: @Cons((), st.box),
|
box: @Cons((), st.box),
|
||||||
unique: ~Cons((), @*st.unique),
|
unique: ~Cons((), @*st.unique),
|
||||||
fn_box: fn@() -> @nillist { @Cons((), fn_box()) },
|
fn_box: fn@() -> @nillist { @Cons((), fn_box()) },
|
||||||
|
@ -97,7 +96,7 @@ fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||||
~Cons((), @*st.tuple.second())),
|
~Cons((), @*st.tuple.second())),
|
||||||
vec: st.vec + ~[@Cons((), st.vec.last())],
|
vec: st.vec + ~[@Cons((), st.vec.last())],
|
||||||
res: r(@Cons((), st.res._l))
|
res: r(@Cons((), st.res._l))
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue