Skip to content

Commit 91e0bc9

Browse files
tedhorstbrson
authored andcommitted
---
yaml --- r: 14042 b: refs/heads/try c: 9b46e87 h: refs/heads/master v: v3
1 parent 801a084 commit 91e0bc9

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 63ae16f7527391c6b1c6168f0f4d46857ce6ec2d
5+
refs/heads/try: 9b46e875cc1a26dd899011559445cdce4ee99678
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/test/bench/shootout-mandelbrot.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
// http://shootout.alioth.debian.org/
33
// u64q/program.php?test=mandelbrot&lang=python3&id=2
44
//
5-
// takes 2 optional numeric args: square image size and yield frequency
5+
// takes 3 optional args:
6+
// square image size, defaults to 80_u
7+
// yield frequency, defaults to 10_u (yield every 10 spawns)
8+
// output path, default is "" (no output), "-" means stdout
9+
//
610
// in the shootout, they use 16000 as image size
711
// yield frequency doesn't seem to have much effect
812
//
9-
// writes pbm image to stdout
13+
// writes pbm image to output path
1014

1115
use std;
1216
import std::io::writer_util;
@@ -72,12 +76,33 @@ fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
7276
comm::send(ch, {i:i, b:crv});
7377
}
7478

75-
fn writer(writech: comm::chan<comm::chan<line>>, size: uint)
79+
type devnull = {dn: int};
80+
81+
impl of std::io::writer for devnull {
82+
fn write(_b: [const u8]) {}
83+
fn seek(_i: int, _s: std::io::seek_style) {}
84+
fn tell() -> uint {0_u}
85+
fn flush() -> int {0}
86+
}
87+
88+
fn writer(path: str, writech: comm::chan<comm::chan<line>>, size: uint)
7689
{
7790
let p: comm::port<line> = comm::port();
7891
let ch = comm::chan(p);
7992
comm::send(writech, ch);
80-
let cout = std::io::stdout();
93+
let cout: std::io::writer = alt path {
94+
"" {
95+
{dn: 0} as std::io::writer
96+
}
97+
"-" {
98+
std::io::stdout()
99+
}
100+
_ {
101+
result::get(
102+
std::io::file_writer(path,
103+
[std::io::create, std::io::truncate]))
104+
}
105+
};
81106
cout.write_line("P4");
82107
cout.write_line(#fmt("%u %u", size, size));
83108
let lines = std::map::new_uint_hash();
@@ -125,10 +150,16 @@ fn main(argv: [str])
125150
else {
126151
uint::from_str(argv[2])
127152
};
153+
let path = if vec::len(argv) < 4_u {
154+
""
155+
}
156+
else {
157+
argv[3]
158+
};
128159
let writep = comm::port();
129160
let writech = comm::chan(writep);
130161
task::spawn {
131-
|| writer(writech, size);
162+
|| writer(path, writech, size);
132163
};
133164
let ch = comm::recv(writep);
134165
uint::range(0_u, size) {

0 commit comments

Comments
 (0)