Skip to content

update mandelbrot to pipes, a few other updates #4239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions src/test/bench/shootout-mandelbrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
// http://shootout.alioth.debian.org/
// u64q/program.php?test=mandelbrot&lang=python3&id=2
//
// takes 3 optional args:
// takes 2 optional args:
// square image size, defaults to 80_u
// yield frequency, defaults to 10_u (yield every 10 spawns)
// output path, default is "" (no output), "-" means stdout
//
// in the shootout, they use 16000 as image size
// yield frequency doesn't seem to have much effect
//
// writes pbm image to output path

#[legacy_modes];

extern mod std;
use io::WriterUtil;
use std::map::HashMap;
Expand Down Expand Up @@ -51,7 +47,7 @@ impl cmplx : ops::Add<cmplx,cmplx> {
}
}

type line = {i: uint, b: ~[u8]};
struct Line {i: uint, b: ~[u8]}

pure fn cabs(x: cmplx) -> f64
{
Expand Down Expand Up @@ -87,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
rv
}

fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<line>) -> ()
fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
{
let mut crv = ~[];
let incr = 2f64/(size as f64);
Expand All @@ -97,22 +93,22 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<line>) -> ()
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
crv.push(fillbyte(x, incr));
};
oldcomm::send(ch, {i:i, b:crv});
oldcomm::send(ch, Line {i:i, b: move crv});
}

type devnull = {dn: int};

impl devnull: io::Writer {
fn write(_b: &[const u8]) {}
fn seek(+_i: int, +_s: io::SeekStyle) {}
fn seek(_i: int, _s: io::SeekStyle) {}
fn tell() -> uint {0_u}
fn flush() -> int {0}
fn get_type() -> io::WriterType { io::File }
}

fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
{
let p: oldcomm::Port<line> = oldcomm::Port();
let p: oldcomm::Port<Line> = oldcomm::Port();
let ch = oldcomm::Chan(&p);
oldcomm::send(writech, ch);
let cout: io::Writer = match path {
Expand Down Expand Up @@ -164,16 +160,13 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"4000", ~"10"]
~[~"", ~"4000"]
} else {
args
};

let path = if vec::len(args) < 4_u { ~"" }
else { copy args[3] }; // FIXME: bad for perf

let yieldevery = if vec::len(args) < 3_u { 10_u }
else { uint::from_str(args[2]).get() };
let path = if vec::len(args) < 3_u { ~"" }
else { copy args[2] }; // FIXME: bad for perf

let size = if vec::len(args) < 2_u { 80_u }
else { uint::from_str(args[1]).get() };
Expand All @@ -185,10 +178,6 @@ fn main() {
};
let ch = oldcomm::recv(writep);
for uint::range(0_u, size) |j| {
task::spawn(|| chanmb(j, size, ch) );
if j % yieldevery == 0_u {
debug!("Y %u", j);
task::yield();
};
do task::spawn { chanmb(j, size, ch) };
};
}