Convert benchmarks to istrs. Issue #855
This commit is contained in:
parent
04700066f3
commit
cb55ef6e12
7 changed files with 97 additions and 103 deletions
|
|
@ -6,34 +6,33 @@
|
|||
*/
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
|
||||
fn b1() -> istr { ret ~"# of beer on the wall, # of beer."; }
|
||||
|
||||
fn b2() -> str {
|
||||
ret "Take one down and pass it around, # of beer on the wall.";
|
||||
fn b2() -> istr {
|
||||
ret ~"Take one down and pass it around, # of beer on the wall.";
|
||||
}
|
||||
|
||||
fn b7() -> str {
|
||||
ret "No more bottles of beer on the wall, no more bottles of beer.";
|
||||
fn b7() -> istr {
|
||||
ret ~"No more bottles of beer on the wall, no more bottles of beer.";
|
||||
}
|
||||
|
||||
fn b8() -> str {
|
||||
ret "Go to the store and buy some more, # of beer on the wall.";
|
||||
fn b8() -> istr {
|
||||
ret ~"Go to the store and buy some more, # of beer on the wall.";
|
||||
}
|
||||
|
||||
fn sub(t: str, n: int) -> str {
|
||||
let b: str = "";
|
||||
fn sub(t: &istr, n: int) -> istr {
|
||||
let b: istr = ~"";
|
||||
let i: uint = 0u;
|
||||
let ns: str;
|
||||
let ns: istr;
|
||||
alt n {
|
||||
0 { ns = "no more bottles"; }
|
||||
1 { ns = "1 bottle"; }
|
||||
_ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
|
||||
0 { ns = ~"no more bottles"; }
|
||||
1 { ns = ~"1 bottle"; }
|
||||
_ { ns = int::to_str(n, 10u) + ~" bottles"; }
|
||||
}
|
||||
while i < str::byte_len(t) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
|
||||
while i < istr::byte_len(t) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { istr::push_byte(b, t[i]); }
|
||||
i += 1u;
|
||||
}
|
||||
ret b;
|
||||
|
|
|
|||
|
|
@ -6,34 +6,33 @@
|
|||
*/
|
||||
use std;
|
||||
import std::int;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
|
||||
fn b1() -> istr { ret ~"# of beer on the wall, # of beer."; }
|
||||
|
||||
fn b2() -> str {
|
||||
ret "Take one down and pass it around, # of beer on the wall.";
|
||||
fn b2() -> istr {
|
||||
ret ~"Take one down and pass it around, # of beer on the wall.";
|
||||
}
|
||||
|
||||
fn b7() -> str {
|
||||
ret "No more bottles of beer on the wall, no more bottles of beer.";
|
||||
fn b7() -> istr {
|
||||
ret ~"No more bottles of beer on the wall, no more bottles of beer.";
|
||||
}
|
||||
|
||||
fn b8() -> str {
|
||||
ret "Go to the store and buy some more, # of beer on the wall.";
|
||||
fn b8() -> istr {
|
||||
ret ~"Go to the store and buy some more, # of beer on the wall.";
|
||||
}
|
||||
|
||||
fn sub(t: str, n: int) -> str {
|
||||
let b: str = "";
|
||||
fn sub(t: &istr, n: int) -> istr {
|
||||
let b: istr = ~"";
|
||||
let i: uint = 0u;
|
||||
let ns: str;
|
||||
let ns: istr;
|
||||
alt n {
|
||||
0 { ns = "no more bottles"; }
|
||||
1 { ns = "1 bottle"; }
|
||||
_ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
|
||||
0 { ns = ~"no more bottles"; }
|
||||
1 { ns = ~"1 bottle"; }
|
||||
_ { ns = int::to_str(n, 10u) + ~" bottles"; }
|
||||
}
|
||||
while i < str::byte_len(t) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
|
||||
while i < istr::byte_len(t) {
|
||||
if t[i] == '#' as u8 { b += ns; } else { istr::push_byte(b, t[i]); }
|
||||
i += 1u;
|
||||
}
|
||||
ret b;
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
*/
|
||||
use std;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::uint;
|
||||
import std::int;
|
||||
import std::istr;
|
||||
|
||||
fn LINE_LENGTH() -> uint { ret 60u; }
|
||||
|
||||
|
|
@ -43,26 +43,27 @@ fn select_random(r: u32, genelist: &[aminoacids]) -> char {
|
|||
ret bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r);
|
||||
}
|
||||
|
||||
fn make_random_fasta(id: str, desc: str, genelist: &[aminoacids], n: int) {
|
||||
log ">" + id + " " + desc;
|
||||
fn make_random_fasta(id: &istr, desc: &istr,
|
||||
genelist: &[aminoacids], n: int) {
|
||||
log ~">" + id + ~" " + desc;
|
||||
let rng = myrandom(std::rand::mk_rng().next());
|
||||
let op: str = "";
|
||||
let op: istr = ~"";
|
||||
for each i: uint in uint::range(0u, n as uint) {
|
||||
str::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
|
||||
if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
|
||||
istr::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
|
||||
if istr::byte_len(op) >= LINE_LENGTH() { log op; op = ~""; }
|
||||
}
|
||||
if str::byte_len(op) > 0u { log op; }
|
||||
if istr::byte_len(op) > 0u { log op; }
|
||||
}
|
||||
|
||||
fn make_repeat_fasta(id: str, desc: str, s: str, n: int) {
|
||||
log ">" + id + " " + desc;
|
||||
let op: str = "";
|
||||
let sl: uint = str::byte_len(s);
|
||||
fn make_repeat_fasta(id: &istr, desc: &istr, s: &istr, n: int) {
|
||||
log ~">" + id + ~" " + desc;
|
||||
let op: istr = ~"";
|
||||
let sl: uint = istr::byte_len(s);
|
||||
for each i: uint in uint::range(0u, n as uint) {
|
||||
str::push_byte(op, s[i % sl]);
|
||||
if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
|
||||
istr::push_byte(op, s[i % sl]);
|
||||
if istr::byte_len(op) >= LINE_LENGTH() { log op; op = ~""; }
|
||||
}
|
||||
if str::byte_len(op) > 0u { log op; }
|
||||
if istr::byte_len(op) > 0u { log op; }
|
||||
}
|
||||
|
||||
fn acid(ch: char, prob: u32) -> aminoacids { ret {ch: ch, prob: prob}; }
|
||||
|
|
@ -77,16 +78,17 @@ fn main(args: [str]) {
|
|||
let homosapiens: [aminoacids] =
|
||||
make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
|
||||
acid('t', 30u32)]);
|
||||
let alu: str =
|
||||
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
|
||||
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
|
||||
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
|
||||
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
|
||||
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
|
||||
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
|
||||
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
|
||||
let alu: istr =
|
||||
~"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
|
||||
~"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
|
||||
~"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
|
||||
~"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
|
||||
~"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
|
||||
~"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
|
||||
~"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
|
||||
let n: int = 512;
|
||||
make_repeat_fasta("ONE", "Homo sapiens alu", alu, n * 2);
|
||||
make_random_fasta("TWO", "IUB ambiguity codes", iub, n * 3);
|
||||
make_random_fasta("THREE", "Homo sapiens frequency", homosapiens, n * 5);
|
||||
make_repeat_fasta(~"ONE", ~"Homo sapiens alu", alu, n * 2);
|
||||
make_random_fasta(~"TWO", ~"IUB ambiguity codes", iub, n * 3);
|
||||
make_random_fasta(~"THREE", ~"Homo sapiens frequency",
|
||||
homosapiens, n * 5);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use std;
|
|||
import std::vec;
|
||||
import std::uint;
|
||||
import std::time;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::int::range;
|
||||
import std::io;
|
||||
|
|
@ -50,8 +49,7 @@ fn fib(n: int) -> int {
|
|||
|
||||
type config = {stress: bool};
|
||||
|
||||
fn parse_opts(argv: [str]) -> config {
|
||||
let argv = istr::from_estrs(argv);
|
||||
fn parse_opts(argv: &[istr]) -> config {
|
||||
let opts = [getopts::optflag(~"stress")];
|
||||
|
||||
let opt_args = vec::slice(argv, 1u, vec::len(argv));
|
||||
|
|
@ -82,6 +80,7 @@ fn stress(num_tasks: int) {
|
|||
}
|
||||
|
||||
fn main(argv: [str]) {
|
||||
let argv = istr::from_estrs(argv);
|
||||
if vec::len(argv) == 1u {
|
||||
assert (fib(8) == 21);
|
||||
log fib(8);
|
||||
|
|
@ -93,7 +92,7 @@ fn main(argv: [str]) {
|
|||
if opts.stress {
|
||||
stress(2);
|
||||
} else {
|
||||
let max = uint::parse_buf(str::bytes(argv[1]), 10u) as int;
|
||||
let max = uint::parse_buf(istr::bytes(argv[1]), 10u) as int;
|
||||
|
||||
let num_trials = 10;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std;
|
|||
import std::vec;
|
||||
import std::task;
|
||||
import std::uint;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
|
||||
fn f(n: uint) {
|
||||
let i = 0u;
|
||||
|
|
@ -13,12 +13,11 @@ fn f(n: uint) {
|
|||
|
||||
fn g() { }
|
||||
|
||||
fn main(args: [str]) {
|
||||
|
||||
fn main(args: [istr]) {
|
||||
let n =
|
||||
if vec::len(args) < 2u {
|
||||
10u
|
||||
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
|
||||
} else { uint::parse_buf(istr::bytes(args[1]), 10u) };
|
||||
let i = 0u;
|
||||
while i < n { task::spawn(bind f(n)); i += 1u; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use std;
|
|||
import option = std::option::t;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::treemap;
|
||||
import std::vec;
|
||||
|
|
@ -35,7 +34,7 @@ fn map(filename: &[u8], emit: &map_reduce::putter<[u8], int>) {
|
|||
|
||||
while true {
|
||||
alt read_word(f) {
|
||||
some(w) { emit(str::bytes(w), 1); }
|
||||
some(w) { emit(istr::bytes(w), 1); }
|
||||
none. { break; }
|
||||
}
|
||||
}
|
||||
|
|
@ -198,12 +197,12 @@ mod map_reduce {
|
|||
}
|
||||
}
|
||||
|
||||
fn main(argv: [str]) {
|
||||
fn main(argv: [istr]) {
|
||||
if vec::len(argv) < 2u {
|
||||
let out = io::stdout();
|
||||
|
||||
out.write_line(
|
||||
#ifmt["Usage: %s <filename> ...", istr::from_estr(argv[0])]);
|
||||
#ifmt["Usage: %s <filename> ...", argv[0]]);
|
||||
|
||||
// TODO: run something just to make sure the code hasn't
|
||||
// broken yet. This is the unit test mode of this program.
|
||||
|
|
@ -213,7 +212,7 @@ fn main(argv: [str]) {
|
|||
|
||||
let iargs = [];
|
||||
for a in vec::slice(argv, 1u, vec::len(argv)) {
|
||||
iargs += [str::bytes(a)];
|
||||
iargs += [istr::bytes(a)];
|
||||
}
|
||||
|
||||
// We can get by with 8k stacks, and we'll probably exhaust our
|
||||
|
|
@ -228,20 +227,20 @@ fn main(argv: [str]) {
|
|||
let elapsed = stop - start;
|
||||
elapsed /= 1000000u64;
|
||||
|
||||
log_err "MapReduce completed in " +
|
||||
istr::to_estr(u64::str(elapsed)) + "ms";
|
||||
log_err ~"MapReduce completed in " +
|
||||
u64::str(elapsed) + ~"ms";
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option<str> {
|
||||
let w = "";
|
||||
fn read_word(r: io::reader) -> option<istr> {
|
||||
let w = ~"";
|
||||
|
||||
while !r.eof() {
|
||||
let c = r.read_char();
|
||||
|
||||
|
||||
if is_word_char(c) {
|
||||
w += str::from_char(c);
|
||||
} else { if w != "" { ret some(w); } }
|
||||
w += istr::from_char(c);
|
||||
} else { if w != ~"" { ret some(w); } }
|
||||
}
|
||||
ret none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use std;
|
|||
import option = std::option::t;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import std::map;
|
||||
import std::vec;
|
||||
|
|
@ -30,8 +29,8 @@ import std::comm::port;
|
|||
import std::comm::recv;
|
||||
import std::comm::send;
|
||||
|
||||
fn map(filename: str, emit: map_reduce::putter) {
|
||||
let f = io::file_reader(istr::from_estr(filename));
|
||||
fn map(filename: &istr, emit: map_reduce::putter) {
|
||||
let f = io::file_reader(filename);
|
||||
|
||||
|
||||
while true {
|
||||
|
|
@ -39,7 +38,7 @@ fn map(filename: str, emit: map_reduce::putter) {
|
|||
}
|
||||
}
|
||||
|
||||
fn reduce(word: str, get: map_reduce::getter) {
|
||||
fn reduce(word: &istr, get: map_reduce::getter) {
|
||||
let count = 0;
|
||||
|
||||
|
||||
|
|
@ -53,48 +52,47 @@ mod map_reduce {
|
|||
export reducer;
|
||||
export map_reduce;
|
||||
|
||||
type putter = fn(str, int);
|
||||
type putter = fn(&istr, int);
|
||||
|
||||
type mapper = fn(str, putter);
|
||||
type mapper = fn(&istr, putter);
|
||||
|
||||
type getter = fn() -> option<int>;
|
||||
|
||||
type reducer = fn(str, getter);
|
||||
type reducer = fn(&istr, getter);
|
||||
|
||||
tag ctrl_proto {
|
||||
find_reducer([u8], chan<chan<reduce_proto>>);
|
||||
find_reducer(istr, chan<chan<reduce_proto>>);
|
||||
mapper_done;
|
||||
}
|
||||
|
||||
tag reduce_proto { emit_val(int); done; ref; release; }
|
||||
|
||||
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: &[str])
|
||||
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: &[istr])
|
||||
-> [joinable_task] {
|
||||
let tasks = [];
|
||||
for i: str in inputs {
|
||||
for i: istr in inputs {
|
||||
tasks += [task::spawn_joinable(bind map_task(ctrl, i))];
|
||||
}
|
||||
ret tasks;
|
||||
}
|
||||
|
||||
fn map_task(ctrl: chan<ctrl_proto>, input: str) {
|
||||
fn map_task(ctrl: chan<ctrl_proto>, input: &istr) {
|
||||
// log_err "map_task " + input;
|
||||
let intermediates = map::new_str_hash();
|
||||
|
||||
fn emit(im: &map::hashmap<istr, chan<reduce_proto>>,
|
||||
ctrl: chan<ctrl_proto>, key: str, val: int) {
|
||||
ctrl: chan<ctrl_proto>, key: &istr, val: int) {
|
||||
let c;
|
||||
alt im.find(istr::from_estr(key)) {
|
||||
alt im.find(key) {
|
||||
some(_c) {
|
||||
|
||||
c = _c
|
||||
}
|
||||
none. {
|
||||
let p = port();
|
||||
let keyi = str::bytes(key);
|
||||
send(ctrl, find_reducer(keyi, chan(p)));
|
||||
send(ctrl, find_reducer(key, chan(p)));
|
||||
c = recv(p);
|
||||
im.insert(istr::from_estr(key), c);
|
||||
im.insert(key, c);
|
||||
send(c, ref);
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +109,7 @@ mod map_reduce {
|
|||
send(ctrl, mapper_done);
|
||||
}
|
||||
|
||||
fn reduce_task(key: str, out: chan<chan<reduce_proto>>) {
|
||||
fn reduce_task(key: &istr, out: chan<chan<reduce_proto>>) {
|
||||
let p = port();
|
||||
|
||||
send(out, chan(p));
|
||||
|
|
@ -141,7 +139,7 @@ mod map_reduce {
|
|||
reduce(key, bind get(p, ref_count, is_done));
|
||||
}
|
||||
|
||||
fn map_reduce(inputs: &[str]) {
|
||||
fn map_reduce(inputs: &[istr]) {
|
||||
let ctrl = port::<ctrl_proto>();
|
||||
|
||||
// This task becomes the master control task. It task::_spawns
|
||||
|
|
@ -161,9 +159,8 @@ mod map_reduce {
|
|||
// log_err "received mapper terminated.";
|
||||
num_mappers -= 1;
|
||||
}
|
||||
find_reducer(ki, cc) {
|
||||
find_reducer(k, cc) {
|
||||
let c;
|
||||
let k = istr::unsafe_from_bytes(ki);
|
||||
// log_err "finding reducer for " + k;
|
||||
alt reducers.find(k) {
|
||||
some(_c) {
|
||||
|
|
@ -175,7 +172,7 @@ mod map_reduce {
|
|||
let p = port();
|
||||
tasks +=
|
||||
[task::spawn_joinable(
|
||||
bind reduce_task(istr::to_estr(k), chan(p)))];
|
||||
bind reduce_task(k, chan(p)))];
|
||||
c = recv(p);
|
||||
reducers.insert(k, c);
|
||||
}
|
||||
|
|
@ -194,12 +191,12 @@ mod map_reduce {
|
|||
}
|
||||
}
|
||||
|
||||
fn main(argv: [str]) {
|
||||
fn main(argv: [istr]) {
|
||||
if vec::len(argv) < 2u {
|
||||
let out = io::stdout();
|
||||
|
||||
out.write_line(
|
||||
#ifmt["Usage: %s <filename> ...", istr::from_estr(argv[0])]);
|
||||
#ifmt["Usage: %s <filename> ...", argv[0]]);
|
||||
|
||||
// TODO: run something just to make sure the code hasn't
|
||||
// broken yet. This is the unit test mode of this program.
|
||||
|
|
@ -222,16 +219,16 @@ fn main(argv: [str]) {
|
|||
log_err ~"MapReduce completed in " + u64::str(elapsed) + ~"ms";
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option<str> {
|
||||
let w = "";
|
||||
fn read_word(r: io::reader) -> option<istr> {
|
||||
let w = ~"";
|
||||
|
||||
while !r.eof() {
|
||||
let c = r.read_char();
|
||||
|
||||
|
||||
if is_word_char(c) {
|
||||
w += str::from_char(c);
|
||||
} else { if w != "" { ret some(w); } }
|
||||
w += istr::from_char(c);
|
||||
} else { if w != ~"" { ret some(w); } }
|
||||
}
|
||||
ret none;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue