bench: Remove usage of fmt!

This commit is contained in:
Alex Crichton 2013-09-29 23:13:47 -07:00
parent 02054ac8a1
commit 73c6c9109f
13 changed files with 55 additions and 54 deletions

View File

@ -128,7 +128,7 @@ fn write_header(header: &str) {
} }
fn write_row(label: &str, value: float) { fn write_row(label: &str, value: float) {
io::stdout().write_str(fmt!("%30s %f s\n", label, value)); io::stdout().write_str(format!("{:30s} {} s\n", label, value));
} }
fn write_results(label: &str, results: &Results) { fn write_results(label: &str, results: &Results) {

View File

@ -133,7 +133,7 @@ fn is_utf8_ascii() {
for _ in range(0u, 20000) { for _ in range(0u, 20000) {
v.push('b' as u8); v.push('b' as u8);
if !str::is_utf8(v) { if !str::is_utf8(v) {
fail!("is_utf8 failed"); fail2!("is_utf8 failed");
} }
} }
} }
@ -144,7 +144,7 @@ fn is_utf8_multibyte() {
for _ in range(0u, 5000) { for _ in range(0u, 5000) {
v.push_all(s.as_bytes()); v.push_all(s.as_bytes());
if !str::is_utf8(v) { if !str::is_utf8(v) {
fail!("is_utf8 failed"); fail2!("is_utf8 failed");
} }
} }
} }

View File

@ -25,6 +25,6 @@ fn main() {
for i in range(0u, n) { for i in range(0u, n) {
let x = i.to_str(); let x = i.to_str();
info!(x); info2!("{}", x);
} }
} }

View File

@ -42,7 +42,7 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
match requests.try_recv() { match requests.try_recv() {
Some(get_count) => { responses.send(count.clone()); } Some(get_count) => { responses.send(count.clone()); }
Some(bytes(b)) => { Some(bytes(b)) => {
//error!("server: received %? bytes", b); //error2!("server: received {:?} bytes", b);
count += b; count += b;
} }
None => { done = true; } None => { done = true; }
@ -50,7 +50,7 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
} }
} }
responses.send(count); responses.send(count);
//error!("server exiting"); //error2!("server exiting");
} }
fn run(args: &[~str]) { fn run(args: &[~str]) {
@ -70,10 +70,10 @@ fn run(args: &[~str]) {
builder.future_result(|r| worker_results.push(r)); builder.future_result(|r| worker_results.push(r));
do builder.spawn { do builder.spawn {
for _ in range(0u, size / workers) { for _ in range(0u, size / workers) {
//error!("worker %?: sending %? bytes", i, num_bytes); //error2!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes)); to_child.send(bytes(num_bytes));
} }
//error!("worker %? exiting", i); //error2!("worker {:?} exiting", i);
} }
} }
do task::spawn || { do task::spawn || {
@ -84,16 +84,16 @@ fn run(args: &[~str]) {
r.recv(); r.recv();
} }
//error!("sending stop message"); //error2!("sending stop message");
to_child.send(stop); to_child.send(stop);
move_out(to_child); move_out(to_child);
let result = from_child.recv(); let result = from_child.recv();
let end = extra::time::precise_time_s(); let end = extra::time::precise_time_s();
let elapsed = end - start; let elapsed = end - start;
io::stdout().write_str(fmt!("Count is %?\n", result)); io::stdout().write_str(format!("Count is {:?}\n", result));
io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed)); io::stdout().write_str(format!("Test took {:?} seconds\n", elapsed));
let thruput = ((size / workers * workers) as float) / (elapsed as float); let thruput = ((size / workers * workers) as float) / (elapsed as float);
io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput)); io::stdout().write_str(format!("Throughput={} per sec\n", thruput));
assert_eq!(result, num_bytes * size); assert_eq!(result, num_bytes * size);
} }
@ -107,6 +107,6 @@ fn main() {
args.clone() args.clone()
}; };
info!("%?", args); info2!("{:?}", args);
run(args); run(args);
} }

View File

@ -37,7 +37,7 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
match requests.try_recv() { match requests.try_recv() {
Some(get_count) => { responses.send(count.clone()); } Some(get_count) => { responses.send(count.clone()); }
Some(bytes(b)) => { Some(bytes(b)) => {
//error!("server: received %? bytes", b); //error2!("server: received {:?} bytes", b);
count += b; count += b;
} }
None => { done = true; } None => { done = true; }
@ -45,7 +45,7 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
} }
} }
responses.send(count); responses.send(count);
//error!("server exiting"); //error2!("server exiting");
} }
fn run(args: &[~str]) { fn run(args: &[~str]) {
@ -64,10 +64,10 @@ fn run(args: &[~str]) {
builder.future_result(|r| worker_results.push(r)); builder.future_result(|r| worker_results.push(r));
do builder.spawn { do builder.spawn {
for _ in range(0u, size / workers) { for _ in range(0u, size / workers) {
//error!("worker %?: sending %? bytes", i, num_bytes); //error2!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes)); to_child.send(bytes(num_bytes));
} }
//error!("worker %? exiting", i); //error2!("worker {:?} exiting", i);
}; };
} }
do task::spawn || { do task::spawn || {
@ -78,16 +78,16 @@ fn run(args: &[~str]) {
r.recv(); r.recv();
} }
//error!("sending stop message"); //error2!("sending stop message");
to_child.send(stop); to_child.send(stop);
move_out(to_child); move_out(to_child);
let result = from_child.recv(); let result = from_child.recv();
let end = extra::time::precise_time_s(); let end = extra::time::precise_time_s();
let elapsed = end - start; let elapsed = end - start;
io::stdout().write_str(fmt!("Count is %?\n", result)); io::stdout().write_str(format!("Count is {:?}\n", result));
io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed)); io::stdout().write_str(format!("Test took {:?} seconds\n", elapsed));
let thruput = ((size / workers * workers) as float) / (elapsed as float); let thruput = ((size / workers * workers) as float) / (elapsed as float);
io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput)); io::stdout().write_str(format!("Throughput={} per sec\n", thruput));
assert_eq!(result, num_bytes * size); assert_eq!(result, num_bytes * size);
} }
@ -101,6 +101,6 @@ fn main() {
args.clone() args.clone()
}; };
info!("%?", args); info2!("{:?}", args);
run(args); run(args);
} }

View File

@ -66,7 +66,7 @@ fn show_digit(nn: uint) -> ~str {
7 => {~"seven"} 7 => {~"seven"}
8 => {~"eight"} 8 => {~"eight"}
9 => {~"nine"} 9 => {~"nine"}
_ => {fail!("expected digits from 0 to 9...")} _ => {fail2!("expected digits from 0 to 9...")}
} }
} }
@ -129,8 +129,8 @@ fn creature(
} }
option::None => { option::None => {
// log creatures met and evil clones of self // log creatures met and evil clones of self
let report = fmt!("%u %s", let report = format!("{} {}",
creatures_met, show_number(evil_clones_met)); creatures_met, show_number(evil_clones_met));
to_rendezvous_log.send(report); to_rendezvous_log.send(report);
break; break;
} }

View File

@ -75,7 +75,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
let b = str::raw::from_utf8(k); let b = str::raw::from_utf8(k);
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use // FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
// to_ascii_move and to_str_move to not do a unnecessary copy. // to_ascii_move and to_str_move to not do a unnecessary copy.
buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v)); buffer.push_str(format!("{} {:0.3f}\n",
b.to_ascii().to_upper().to_str_ascii(), v));
} }
} }
@ -142,11 +143,11 @@ fn make_sequence_processor(sz: uint,
let buffer = match sz { let buffer = match sz {
1u => { sort_and_fmt(&freqs, total) } 1u => { sort_and_fmt(&freqs, total) }
2u => { sort_and_fmt(&freqs, total) } 2u => { sort_and_fmt(&freqs, total) }
3u => { fmt!("%u\t%s", find(&freqs, ~"GGT"), "GGT") } 3u => { format!("{}\t{}", find(&freqs, ~"GGT"), "GGT") }
4u => { fmt!("%u\t%s", find(&freqs, ~"GGTA"), "GGTA") } 4u => { format!("{}\t{}", find(&freqs, ~"GGTA"), "GGTA") }
6u => { fmt!("%u\t%s", find(&freqs, ~"GGTATT"), "GGTATT") } 6u => { format!("{}\t{}", find(&freqs, ~"GGTATT"), "GGTATT") }
12u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATT"), "GGTATTTTAATT") } 12u => { format!("{}\t{}", find(&freqs, ~"GGTATTTTAATT"), "GGTATTTTAATT") }
18u => { fmt!("%u\t%s", find(&freqs, ~"GGTATTTTAATTTATAGT"), "GGTATTTTAATTTATAGT") } 18u => { format!("{}\t{}", find(&freqs, ~"GGTATTTTAATTTATAGT"), "GGTATTTTAATTTATAGT") }
_ => { ~"" } _ => { ~"" }
}; };

View File

@ -66,7 +66,7 @@ fn parse_opts(argv: ~[~str]) -> Config {
Ok(ref m) => { Ok(ref m) => {
return Config {stress: m.opt_present("stress")} return Config {stress: m.opt_present("stress")}
} }
Err(_) => { fail!(); } Err(_) => { fail2!(); }
} }
} }
@ -76,7 +76,7 @@ fn stress_task(id: int) {
let n = 15; let n = 15;
assert_eq!(fib(n), fib(n)); assert_eq!(fib(n), fib(n));
i += 1; i += 1;
error!("%d: Completed %d iterations", id, i); error2!("{}: Completed {} iterations", id, i);
} }
} }
@ -123,8 +123,8 @@ fn main() {
let elapsed = stop - start; let elapsed = stop - start;
out.write_line(fmt!("%d\t%d\t%s", n, fibn, out.write_line(format!("{}\t{}\t{}", n, fibn,
elapsed.to_str())); elapsed.to_str()));
} }
} }
} }

View File

@ -59,8 +59,8 @@ fn main() {
let maxf = max as float; let maxf = max as float;
io::stdout().write_str(fmt!("insert(): %? seconds\n", checkf)); io::stdout().write_str(format!("insert(): {:?} seconds\n", checkf));
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/checkf)); io::stdout().write_str(format!(" : {} op/sec\n", maxf/checkf));
io::stdout().write_str(fmt!("get() : %? seconds\n", appendf)); io::stdout().write_str(format!("get() : {:?} seconds\n", appendf));
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/appendf)); io::stdout().write_str(format!(" : {} op/sec\n", maxf/appendf));
} }

View File

@ -79,7 +79,7 @@ impl Sudoku {
g[row][col] = from_str::<uint>(comps[2]).unwrap() as u8; g[row][col] = from_str::<uint>(comps[2]).unwrap() as u8;
} }
else { else {
fail!("Invalid sudoku file"); fail2!("Invalid sudoku file");
} }
} }
return Sudoku::new(g) return Sudoku::new(g)
@ -87,9 +87,9 @@ impl Sudoku {
pub fn write(&self, writer: @io::Writer) { pub fn write(&self, writer: @io::Writer) {
for row in range(0u8, 9u8) { for row in range(0u8, 9u8) {
writer.write_str(fmt!("%u", self.grid[row][0] as uint)); writer.write_str(format!("{}", self.grid[row][0] as uint));
for col in range(1u8, 9u8) { for col in range(1u8, 9u8) {
writer.write_str(fmt!(" %u", self.grid[row][col] as uint)); writer.write_str(format!(" {}", self.grid[row][col] as uint));
} }
writer.write_char('\n'); writer.write_char('\n');
} }
@ -117,7 +117,7 @@ impl Sudoku {
ptr = ptr + 1u; ptr = ptr + 1u;
} else { } else {
// no: redo this field aft recoloring pred; unless there is none // no: redo this field aft recoloring pred; unless there is none
if ptr == 0u { fail!("No solution found for this sudoku"); } if ptr == 0u { fail2!("No solution found for this sudoku"); }
ptr = ptr - 1u; ptr = ptr - 1u;
} }
} }

View File

@ -31,11 +31,11 @@ fn main() {
fn run(repeat: int, depth: int) { fn run(repeat: int, depth: int) {
for _ in range(0, repeat) { for _ in range(0, repeat) {
info!("starting %.4f", precise_time_s()); info2!("starting {:.4f}", precise_time_s());
do task::try { do task::try {
recurse_or_fail(depth, None) recurse_or_fail(depth, None)
}; };
info!("stopping %.4f", precise_time_s()); info2!("stopping {:.4f}", precise_time_s());
} }
} }
@ -68,8 +68,8 @@ fn r(l: @nillist) -> r {
fn recurse_or_fail(depth: int, st: Option<State>) { fn recurse_or_fail(depth: int, st: Option<State>) {
if depth == 0 { if depth == 0 {
info!("unwinding %.4f", precise_time_s()); info2!("unwinding {:.4f}", precise_time_s());
fail!(); fail2!();
} else { } else {
let depth = depth - 1; let depth = depth - 1;

View File

@ -54,6 +54,6 @@ fn main() {
let (p,c) = comm::stream(); let (p,c) = comm::stream();
child_generation(from_str::<uint>(args[1]).unwrap(), c); child_generation(from_str::<uint>(args[1]).unwrap(), c);
if p.try_recv().is_none() { if p.try_recv().is_none() {
fail!("it happened when we slumbered"); fail2!("it happened when we slumbered");
} }
} }

View File

@ -43,13 +43,13 @@ fn grandchild_group(num_tasks: uint) {
p.recv(); // block forever p.recv(); // block forever
} }
} }
error!("Grandchild group getting started"); error2!("Grandchild group getting started");
for _ in range(0, num_tasks) { for _ in range(0, num_tasks) {
// Make sure all above children are fully spawned; i.e., enlisted in // Make sure all above children are fully spawned; i.e., enlisted in
// their ancestor groups. // their ancestor groups.
po.recv(); po.recv();
} }
error!("Grandchild group ready to go."); error2!("Grandchild group ready to go.");
// Master grandchild task exits early. // Master grandchild task exits early.
} }
@ -59,7 +59,7 @@ fn spawn_supervised_blocking(myname: &str, f: ~fn()) {
builder.future_result(|r| res = Some(r)); builder.future_result(|r| res = Some(r));
builder.supervised(); builder.supervised();
builder.spawn(f); builder.spawn(f);
error!("%s group waiting", myname); error2!("{} group waiting", myname);
let x = res.unwrap().recv(); let x = res.unwrap().recv();
assert_eq!(x, task::Success); assert_eq!(x, task::Success);
} }
@ -85,11 +85,11 @@ fn main() {
grandchild_group(num_tasks); grandchild_group(num_tasks);
} }
// When grandchild group is ready to go, make the middle group exit. // When grandchild group is ready to go, make the middle group exit.
error!("Middle group wakes up and exits"); error2!("Middle group wakes up and exits");
} }
// Grandparent group waits for middle group to be gone, then fails // Grandparent group waits for middle group to be gone, then fails
error!("Grandparent group wakes up and fails"); error2!("Grandparent group wakes up and fails");
fail!(); fail2!();
}; };
assert!(x.is_err()); assert!(x.is_err());
} }