Skip to content

Commit cb55ef6

Browse files
committed
Convert benchmarks to istrs. Issue #855
1 parent 0470006 commit cb55ef6

7 files changed

+97
-103
lines changed

src/test/bench/99bob-iter.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@
66
*/
77
use std;
88
import std::int;
9-
import std::str;
109
import std::istr;
1110

12-
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
11+
fn b1() -> istr { ret ~"# of beer on the wall, # of beer."; }
1312

14-
fn b2() -> str {
15-
ret "Take one down and pass it around, # of beer on the wall.";
13+
fn b2() -> istr {
14+
ret ~"Take one down and pass it around, # of beer on the wall.";
1615
}
1716

18-
fn b7() -> str {
19-
ret "No more bottles of beer on the wall, no more bottles of beer.";
17+
fn b7() -> istr {
18+
ret ~"No more bottles of beer on the wall, no more bottles of beer.";
2019
}
2120

22-
fn b8() -> str {
23-
ret "Go to the store and buy some more, # of beer on the wall.";
21+
fn b8() -> istr {
22+
ret ~"Go to the store and buy some more, # of beer on the wall.";
2423
}
2524

26-
fn sub(t: str, n: int) -> str {
27-
let b: str = "";
25+
fn sub(t: &istr, n: int) -> istr {
26+
let b: istr = ~"";
2827
let i: uint = 0u;
29-
let ns: str;
28+
let ns: istr;
3029
alt n {
31-
0 { ns = "no more bottles"; }
32-
1 { ns = "1 bottle"; }
33-
_ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
30+
0 { ns = ~"no more bottles"; }
31+
1 { ns = ~"1 bottle"; }
32+
_ { ns = int::to_str(n, 10u) + ~" bottles"; }
3433
}
35-
while i < str::byte_len(t) {
36-
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
34+
while i < istr::byte_len(t) {
35+
if t[i] == '#' as u8 { b += ns; } else { istr::push_byte(b, t[i]); }
3736
i += 1u;
3837
}
3938
ret b;

src/test/bench/99bob-simple.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@
66
*/
77
use std;
88
import std::int;
9-
import std::str;
109
import std::istr;
1110

12-
fn b1() -> str { ret "# of beer on the wall, # of beer."; }
11+
fn b1() -> istr { ret ~"# of beer on the wall, # of beer."; }
1312

14-
fn b2() -> str {
15-
ret "Take one down and pass it around, # of beer on the wall.";
13+
fn b2() -> istr {
14+
ret ~"Take one down and pass it around, # of beer on the wall.";
1615
}
1716

18-
fn b7() -> str {
19-
ret "No more bottles of beer on the wall, no more bottles of beer.";
17+
fn b7() -> istr {
18+
ret ~"No more bottles of beer on the wall, no more bottles of beer.";
2019
}
2120

22-
fn b8() -> str {
23-
ret "Go to the store and buy some more, # of beer on the wall.";
21+
fn b8() -> istr {
22+
ret ~"Go to the store and buy some more, # of beer on the wall.";
2423
}
2524

26-
fn sub(t: str, n: int) -> str {
27-
let b: str = "";
25+
fn sub(t: &istr, n: int) -> istr {
26+
let b: istr = ~"";
2827
let i: uint = 0u;
29-
let ns: str;
28+
let ns: istr;
3029
alt n {
31-
0 { ns = "no more bottles"; }
32-
1 { ns = "1 bottle"; }
33-
_ { ns = istr::to_estr(int::to_str(n, 10u) + ~" bottles"); }
30+
0 { ns = ~"no more bottles"; }
31+
1 { ns = ~"1 bottle"; }
32+
_ { ns = int::to_str(n, 10u) + ~" bottles"; }
3433
}
35-
while i < str::byte_len(t) {
36-
if t[i] == '#' as u8 { b += ns; } else { str::push_byte(b, t[i]); }
34+
while i < istr::byte_len(t) {
35+
if t[i] == '#' as u8 { b += ns; } else { istr::push_byte(b, t[i]); }
3736
i += 1u;
3837
}
3938
ret b;

src/test/bench/shootout-fasta.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88
use std;
99
import std::vec;
10-
import std::str;
1110
import std::uint;
1211
import std::int;
12+
import std::istr;
1313

1414
fn LINE_LENGTH() -> uint { ret 60u; }
1515

@@ -43,26 +43,27 @@ fn select_random(r: u32, genelist: &[aminoacids]) -> char {
4343
ret bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r);
4444
}
4545

46-
fn make_random_fasta(id: str, desc: str, genelist: &[aminoacids], n: int) {
47-
log ">" + id + " " + desc;
46+
fn make_random_fasta(id: &istr, desc: &istr,
47+
genelist: &[aminoacids], n: int) {
48+
log ~">" + id + ~" " + desc;
4849
let rng = myrandom(std::rand::mk_rng().next());
49-
let op: str = "";
50+
let op: istr = ~"";
5051
for each i: uint in uint::range(0u, n as uint) {
51-
str::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
52-
if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
52+
istr::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
53+
if istr::byte_len(op) >= LINE_LENGTH() { log op; op = ~""; }
5354
}
54-
if str::byte_len(op) > 0u { log op; }
55+
if istr::byte_len(op) > 0u { log op; }
5556
}
5657

57-
fn make_repeat_fasta(id: str, desc: str, s: str, n: int) {
58-
log ">" + id + " " + desc;
59-
let op: str = "";
60-
let sl: uint = str::byte_len(s);
58+
fn make_repeat_fasta(id: &istr, desc: &istr, s: &istr, n: int) {
59+
log ~">" + id + ~" " + desc;
60+
let op: istr = ~"";
61+
let sl: uint = istr::byte_len(s);
6162
for each i: uint in uint::range(0u, n as uint) {
62-
str::push_byte(op, s[i % sl]);
63-
if str::byte_len(op) >= LINE_LENGTH() { log op; op = ""; }
63+
istr::push_byte(op, s[i % sl]);
64+
if istr::byte_len(op) >= LINE_LENGTH() { log op; op = ~""; }
6465
}
65-
if str::byte_len(op) > 0u { log op; }
66+
if istr::byte_len(op) > 0u { log op; }
6667
}
6768

6869
fn acid(ch: char, prob: u32) -> aminoacids { ret {ch: ch, prob: prob}; }
@@ -77,16 +78,17 @@ fn main(args: [str]) {
7778
let homosapiens: [aminoacids] =
7879
make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
7980
acid('t', 30u32)]);
80-
let alu: str =
81-
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
82-
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
83-
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
84-
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
85-
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
86-
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
87-
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
81+
let alu: istr =
82+
~"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
83+
~"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
84+
~"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
85+
~"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
86+
~"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
87+
~"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
88+
~"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
8889
let n: int = 512;
89-
make_repeat_fasta("ONE", "Homo sapiens alu", alu, n * 2);
90-
make_random_fasta("TWO", "IUB ambiguity codes", iub, n * 3);
91-
make_random_fasta("THREE", "Homo sapiens frequency", homosapiens, n * 5);
90+
make_repeat_fasta(~"ONE", ~"Homo sapiens alu", alu, n * 2);
91+
make_random_fasta(~"TWO", ~"IUB ambiguity codes", iub, n * 3);
92+
make_random_fasta(~"THREE", ~"Homo sapiens frequency",
93+
homosapiens, n * 5);
9294
}

src/test/bench/shootout-pfib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std;
1414
import std::vec;
1515
import std::uint;
1616
import std::time;
17-
import std::str;
1817
import std::istr;
1918
import std::int::range;
2019
import std::io;
@@ -50,8 +49,7 @@ fn fib(n: int) -> int {
5049

5150
type config = {stress: bool};
5251

53-
fn parse_opts(argv: [str]) -> config {
54-
let argv = istr::from_estrs(argv);
52+
fn parse_opts(argv: &[istr]) -> config {
5553
let opts = [getopts::optflag(~"stress")];
5654

5755
let opt_args = vec::slice(argv, 1u, vec::len(argv));
@@ -82,6 +80,7 @@ fn stress(num_tasks: int) {
8280
}
8381

8482
fn main(argv: [str]) {
83+
let argv = istr::from_estrs(argv);
8584
if vec::len(argv) == 1u {
8685
assert (fib(8) == 21);
8786
log fib(8);
@@ -93,7 +92,7 @@ fn main(argv: [str]) {
9392
if opts.stress {
9493
stress(2);
9594
} else {
96-
let max = uint::parse_buf(str::bytes(argv[1]), 10u) as int;
95+
let max = uint::parse_buf(istr::bytes(argv[1]), 10u) as int;
9796

9897
let num_trials = 10;
9998

src/test/bench/task-perf-spawnalot.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std;
22
import std::vec;
33
import std::task;
44
import std::uint;
5-
import std::str;
5+
import std::istr;
66

77
fn f(n: uint) {
88
let i = 0u;
@@ -13,12 +13,11 @@ fn f(n: uint) {
1313

1414
fn g() { }
1515

16-
fn main(args: [str]) {
17-
16+
fn main(args: [istr]) {
1817
let n =
1918
if vec::len(args) < 2u {
2019
10u
21-
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
20+
} else { uint::parse_buf(istr::bytes(args[1]), 10u) };
2221
let i = 0u;
2322
while i < n { task::spawn(bind f(n)); i += 1u; }
2423
}

src/test/bench/task-perf-word-count-generic.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std;
1313
import option = std::option::t;
1414
import std::option::some;
1515
import std::option::none;
16-
import std::str;
1716
import std::istr;
1817
import std::treemap;
1918
import std::vec;
@@ -35,7 +34,7 @@ fn map(filename: &[u8], emit: &map_reduce::putter<[u8], int>) {
3534

3635
while true {
3736
alt read_word(f) {
38-
some(w) { emit(str::bytes(w), 1); }
37+
some(w) { emit(istr::bytes(w), 1); }
3938
none. { break; }
4039
}
4140
}
@@ -198,12 +197,12 @@ mod map_reduce {
198197
}
199198
}
200199

201-
fn main(argv: [str]) {
200+
fn main(argv: [istr]) {
202201
if vec::len(argv) < 2u {
203202
let out = io::stdout();
204203

205204
out.write_line(
206-
#ifmt["Usage: %s <filename> ...", istr::from_estr(argv[0])]);
205+
#ifmt["Usage: %s <filename> ...", argv[0]]);
207206

208207
// TODO: run something just to make sure the code hasn't
209208
// broken yet. This is the unit test mode of this program.
@@ -213,7 +212,7 @@ fn main(argv: [str]) {
213212

214213
let iargs = [];
215214
for a in vec::slice(argv, 1u, vec::len(argv)) {
216-
iargs += [str::bytes(a)];
215+
iargs += [istr::bytes(a)];
217216
}
218217

219218
// We can get by with 8k stacks, and we'll probably exhaust our
@@ -228,20 +227,20 @@ fn main(argv: [str]) {
228227
let elapsed = stop - start;
229228
elapsed /= 1000000u64;
230229

231-
log_err "MapReduce completed in " +
232-
istr::to_estr(u64::str(elapsed)) + "ms";
230+
log_err ~"MapReduce completed in " +
231+
u64::str(elapsed) + ~"ms";
233232
}
234233

235-
fn read_word(r: io::reader) -> option<str> {
236-
let w = "";
234+
fn read_word(r: io::reader) -> option<istr> {
235+
let w = ~"";
237236

238237
while !r.eof() {
239238
let c = r.read_char();
240239

241240

242241
if is_word_char(c) {
243-
w += str::from_char(c);
244-
} else { if w != "" { ret some(w); } }
242+
w += istr::from_char(c);
243+
} else { if w != ~"" { ret some(w); } }
245244
}
246245
ret none;
247246
}

0 commit comments

Comments
 (0)