mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
update mandelbrot to pipes, a few other updates
This commit is contained in:
parent
8d438747a5
commit
d30224a3d4
@ -12,18 +12,14 @@
|
|||||||
// http://shootout.alioth.debian.org/
|
// http://shootout.alioth.debian.org/
|
||||||
// u64q/program.php?test=mandelbrot&lang=python3&id=2
|
// u64q/program.php?test=mandelbrot&lang=python3&id=2
|
||||||
//
|
//
|
||||||
// takes 3 optional args:
|
// takes 2 optional args:
|
||||||
// square image size, defaults to 80_u
|
// 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
|
// output path, default is "" (no output), "-" means stdout
|
||||||
//
|
//
|
||||||
// in the shootout, they use 16000 as image size
|
// in the shootout, they use 16000 as image size
|
||||||
// yield frequency doesn't seem to have much effect
|
|
||||||
//
|
//
|
||||||
// writes pbm image to output path
|
// writes pbm image to output path
|
||||||
|
|
||||||
#[legacy_modes];
|
|
||||||
|
|
||||||
extern mod std;
|
extern mod std;
|
||||||
use io::WriterUtil;
|
use io::WriterUtil;
|
||||||
use std::map::HashMap;
|
use std::map::HashMap;
|
||||||
@ -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
|
pure fn cabs(x: cmplx) -> f64
|
||||||
{
|
{
|
||||||
@ -87,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
|||||||
rv
|
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 mut crv = ~[];
|
||||||
let incr = 2f64/(size as f64);
|
let incr = 2f64/(size as f64);
|
||||||
@ -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};
|
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
|
||||||
crv.push(fillbyte(x, incr));
|
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};
|
type devnull = {dn: int};
|
||||||
|
|
||||||
impl devnull: io::Writer {
|
impl devnull: io::Writer {
|
||||||
fn write(_b: &[const u8]) {}
|
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 tell() -> uint {0_u}
|
||||||
fn flush() -> int {0}
|
fn flush() -> int {0}
|
||||||
fn get_type() -> io::WriterType { io::File }
|
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);
|
let ch = oldcomm::Chan(&p);
|
||||||
oldcomm::send(writech, ch);
|
oldcomm::send(writech, ch);
|
||||||
let cout: io::Writer = match path {
|
let cout: io::Writer = match path {
|
||||||
@ -164,16 +160,13 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
|
|||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
||||||
~[~"", ~"4000", ~"10"]
|
~[~"", ~"4000"]
|
||||||
} else {
|
} else {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = if vec::len(args) < 4_u { ~"" }
|
let path = if vec::len(args) < 3_u { ~"" }
|
||||||
else { copy args[3] }; // FIXME: bad for perf
|
else { copy args[2] }; // FIXME: bad for perf
|
||||||
|
|
||||||
let yieldevery = if vec::len(args) < 3_u { 10_u }
|
|
||||||
else { uint::from_str(args[2]).get() };
|
|
||||||
|
|
||||||
let size = if vec::len(args) < 2_u { 80_u }
|
let size = if vec::len(args) < 2_u { 80_u }
|
||||||
else { uint::from_str(args[1]).get() };
|
else { uint::from_str(args[1]).get() };
|
||||||
@ -185,10 +178,6 @@ fn main() {
|
|||||||
};
|
};
|
||||||
let ch = oldcomm::recv(writep);
|
let ch = oldcomm::recv(writep);
|
||||||
for uint::range(0_u, size) |j| {
|
for uint::range(0_u, size) |j| {
|
||||||
task::spawn(|| chanmb(j, size, ch) );
|
do task::spawn { chanmb(j, size, ch) };
|
||||||
if j % yieldevery == 0_u {
|
|
||||||
debug!("Y %u", j);
|
|
||||||
task::yield();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user