Convert benchmarks to ivecs

This commit is contained in:
Brian Anderson 2011-08-11 21:37:27 -07:00
parent 5ed5ae8918
commit b762ba0890
5 changed files with 41 additions and 39 deletions

View File

@ -1,15 +1,15 @@
// Based on Isaac Gouy's fannkuchredux.csharp
use std;
import std::int;
import std::vec;
import std::ivec;
fn fannkuch(n: int) -> int {
fn perm1init(i: uint) -> int { ret i as int; }
let perm1init_ = perm1init; // Rustboot workaround
let perm = vec::init_elt_mut(0, n as uint);
let perm1 = vec::init_fn_mut(perm1init_, n as uint);
let count = vec::init_elt_mut(0, n as uint);
let perm = ivec::init_elt_mut(0, n as uint);
let perm1 = ivec::init_fn_mut(perm1init_, n as uint);
let count = ivec::init_elt_mut(0, n as uint);
let f = 0;
let i = 0;
let k = 0;

View File

@ -6,7 +6,7 @@
* http://shootout.alioth.debian.org/
*/
use std;
import std::vec;
import std::ivec;
import std::str;
import std::uint;
import std::int;
@ -23,16 +23,16 @@ obj myrandom(mutable last: u32) {
type aminoacids = {ch: char, prob: u32};
fn make_cumulative(aa: vec[aminoacids]) -> vec[aminoacids] {
fn make_cumulative(aa: &[aminoacids]) -> [aminoacids] {
let cp: u32 = 0u32;
let ans: vec[aminoacids] = [];
for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; }
let ans: [aminoacids] = ~[];
for a: aminoacids in aa { cp += a.prob; ans += ~[{ch: a.ch, prob: cp}]; }
ret ans;
}
fn select_random(r: u32, genelist: vec[aminoacids]) -> char {
fn select_random(r: u32, genelist: &[aminoacids]) -> char {
if r < genelist.(0).prob { ret genelist.(0).ch; }
fn bisect(v: vec[aminoacids], lo: uint, hi: uint, target: u32) -> char {
fn bisect(v: &[aminoacids], lo: uint, hi: uint, target: u32) -> char {
if hi > lo + 1u {
let mid: uint = lo + (hi - lo) / 2u;
if target < v.(mid).prob {
@ -40,10 +40,10 @@ fn select_random(r: u32, genelist: vec[aminoacids]) -> char {
} else { be bisect(v, mid, hi, target); }
} else { ret v.(hi).ch; }
}
ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
ret bisect(genelist, 0u, ivec::len[aminoacids](genelist) - 1u, r);
}
fn make_random_fasta(id: str, desc: str, genelist: vec[aminoacids], n: int) {
fn make_random_fasta(id: str, desc: str, genelist: &[aminoacids], n: int) {
log ">" + id + " " + desc;
let rng = myrandom(std::rand::mk_rng().next());
let op: str = "";
@ -68,15 +68,17 @@ fn make_repeat_fasta(id: str, desc: str, s: str, n: int) {
fn acid(ch: char, prob: u32) -> aminoacids { ret {ch: ch, prob: prob}; }
fn main(args: vec[str]) {
let iub: vec[aminoacids] =
make_cumulative([acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
let homosapiens: vec[aminoacids] =
make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
acid('t', 30u32)]);
let iub: [aminoacids] =
make_cumulative(
~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
let homosapiens: [aminoacids] =
make_cumulative(
~[acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
acid('t', 30u32)]);
let alu: str =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +

View File

@ -11,7 +11,6 @@
use std;
import std::vec;
import std::ivec;
import std::uint;
import std::time;
@ -47,13 +46,13 @@ fn fib(n: int) -> int {
type config = {stress: bool};
fn parse_opts(argv: vec[str]) -> config {
let opts = [getopts::optflag("stress")];
fn parse_opts(argv: [str]) -> config {
let opts = ~[getopts::optflag("stress")];
let opt_args = vec::slice(argv, 1u, vec::len(argv));
let opt_args = ivec::slice(argv, 1u, ivec::len(argv));
alt getopts::getopts(opt_args, opts) {
alt getopts::getopts_ivec(opt_args, opts) {
getopts::success(m) { ret {stress: getopts::opt_present(m, "stress")} }
getopts::failure(_) { fail; }
}
@ -78,18 +77,19 @@ fn stress(num_tasks: int) {
}
fn main(argv: vec[str]) {
if vec::len(argv) == 1u {
let iargv = ivec::from_vec(argv);
if ivec::len(iargv) == 1u {
assert (fib(8) == 21);
log fib(8);
} else {
// Interactive mode! Wooo!!!!
let opts = parse_opts(argv);
let opts = parse_opts(iargv);
if opts.stress {
stress(2);
} else {
let max = uint::parse_buf(ivec::to_vec(str::bytes(argv.(1))),
let max = uint::parse_buf(ivec::to_vec(str::bytes(iargv.(1))),
10u) as int;
let num_trials = 10;

View File

@ -1,5 +1,4 @@
use std;
import std::vec;
import std::ivec;
import std::task;
import std::uint;
@ -17,10 +16,11 @@ fn g() {}
fn main(args: vec[str]) {
let n = if vec::len(args) < 2u {
let iargs = ivec::from_vec(args);
let n = if ivec::len(iargs) < 2u {
10u
} else {
uint::parse_buf(ivec::to_vec(str::bytes(args.(1))), 10u)
uint::parse_buf(ivec::to_vec(str::bytes(iargs.(1))), 10u)
};
let i = 0u;
while i < n {

View File

@ -14,7 +14,6 @@ import option = std::option::t;
import std::option::some;
import std::option::none;
import std::str;
import std::vec;
import std::map;
import std::ivec;
import std::io;
@ -79,7 +78,7 @@ mod map_reduce {
tag reduce_proto { emit_val(int); done; ref; release; }
fn start_mappers(ctrl: chan[ctrl_proto], inputs: vec[str]) -> [task] {
fn start_mappers(ctrl: chan[ctrl_proto], inputs: &[str]) -> [task] {
let tasks = ~[];
// log_err "starting mappers";
for i: str in inputs {
@ -166,7 +165,7 @@ mod map_reduce {
// log_err "~reduce_task " + key;
}
fn map_reduce(inputs: vec[str]) {
fn map_reduce(inputs: &[str]) {
let ctrl = port[ctrl_proto]();
// This task becomes the master control task. It spawns others
@ -178,7 +177,7 @@ mod map_reduce {
let tasks = start_mappers(chan(ctrl), inputs);
let num_mappers = vec::len(inputs) as int;
let num_mappers = ivec::len(inputs) as int;
while num_mappers > 0 {
let m;
@ -225,10 +224,11 @@ mod map_reduce {
}
fn main(argv: vec[str]) {
if vec::len(argv) < 2u {
let iargv = ivec::from_vec(argv);
if ivec::len(iargv) < 2u {
let out = io::stdout();
out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
out.write_line(#fmt("Usage: %s <filename> ...", iargv.(0)));
// TODO: run something just to make sure the code hasn't
// broken yet. This is the unit test mode of this program.
@ -242,7 +242,7 @@ fn main(argv: vec[str]) {
let start = time::precise_time_ns();
map_reduce::map_reduce(vec::slice(argv, 1u, vec::len(argv)));
map_reduce::map_reduce(ivec::slice(iargv, 1u, ivec::len(iargv)));
let stop = time::precise_time_ns();
let elapsed = stop - start;