1212// http://shootout.alioth.debian.org/
1313// u64q/program.php?test=mandelbrot&lang=python3&id=2
1414//
15- // takes 3 optional args:
15+ // takes 2 optional args:
1616// square image size, defaults to 80_u
17- // yield frequency, defaults to 10_u (yield every 10 spawns)
1817// output path, default is "" (no output), "-" means stdout
1918//
2019// in the shootout, they use 16000 as image size
21- // yield frequency doesn't seem to have much effect
2220//
2321// writes pbm image to output path
2422
25- #[ legacy_modes] ;
26-
2723extern mod std;
2824use io:: WriterUtil ;
2925use std:: map:: HashMap ;
@@ -51,7 +47,7 @@ impl cmplx : ops::Add<cmplx,cmplx> {
5147 }
5248}
5349
54- type line = { i : uint , b : ~[ u8 ] } ;
50+ struct Line { i : uint , b : ~[ u8 ] }
5551
5652pure fn cabs ( x : cmplx ) -> f64
5753{
@@ -87,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
8783 rv
8884}
8985
90- fn chanmb ( i : uint , size : uint , ch : oldcomm:: Chan < line > ) -> ( )
86+ fn chanmb ( i : uint , size : uint , ch : oldcomm:: Chan < Line > ) -> ( )
9187{
9288 let mut crv = ~[ ] ;
9389 let incr = 2f64 /( size as f64 ) ;
@@ -97,22 +93,22 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<line>) -> ()
9793 let x = cmplx { re : xincr* ( j as f64 ) - 1.5f64 , im : y} ;
9894 crv. push ( fillbyte ( x, incr) ) ;
9995 } ;
100- oldcomm:: send ( ch, { i: i, b: crv} ) ;
96+ oldcomm:: send ( ch, Line { i : i, b : move crv} ) ;
10197}
10298
10399type devnull = { dn : int } ;
104100
105101impl devnull: io:: Writer {
106102 fn write ( _b : & [ const u8 ] ) { }
107- fn seek ( + _i : int , + _s : io:: SeekStyle ) { }
103+ fn seek ( _i : int , _s : io:: SeekStyle ) { }
108104 fn tell ( ) -> uint { 0_ u}
109105 fn flush ( ) -> int { 0 }
110106 fn get_type ( ) -> io:: WriterType { io:: File }
111107}
112108
113- fn writer ( path : ~str , writech : oldcomm:: Chan < oldcomm:: Chan < line > > , size : uint )
109+ fn writer ( path : ~str , writech : oldcomm:: Chan < oldcomm:: Chan < Line > > , size : uint )
114110{
115- let p: oldcomm:: Port < line > = oldcomm:: Port ( ) ;
111+ let p: oldcomm:: Port < Line > = oldcomm:: Port ( ) ;
116112 let ch = oldcomm:: Chan ( & p) ;
117113 oldcomm:: send ( writech, ch) ;
118114 let cout: io:: Writer = match path {
@@ -164,16 +160,13 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
164160fn main ( ) {
165161 let args = os:: args ( ) ;
166162 let args = if os:: getenv ( ~"RUST_BENCH ") . is_some ( ) {
167- ~[ ~"", ~"4000 ", ~" 10 " ]
163+ ~[ ~"", ~"4000 "]
168164 } else {
169165 args
170166 } ;
171167
172- let path = if vec:: len ( args) < 4_ u { ~"" }
173- else { copy args[ 3 ] } ; // FIXME: bad for perf
174-
175- let yieldevery = if vec:: len ( args) < 3_ u { 10_ u }
176- else { uint:: from_str ( args[ 2 ] ) . get ( ) } ;
168+ let path = if vec:: len ( args) < 3_ u { ~"" }
169+ else { copy args[ 2 ] } ; // FIXME: bad for perf
177170
178171 let size = if vec:: len ( args) < 2_ u { 80_ u }
179172 else { uint:: from_str ( args[ 1 ] ) . get ( ) } ;
@@ -185,10 +178,6 @@ fn main() {
185178 } ;
186179 let ch = oldcomm:: recv ( writep) ;
187180 for uint:: range( 0_ u, size) |j| {
188- task:: spawn( || chanmb( j, size, ch) ) ;
189- if j % yieldevery == 0_ u {
190- debug ! ( "Y %u" , j) ;
191- task:: yield ( ) ;
192- } ;
181+ do task:: spawn { chanmb( j, size, ch) } ;
193182 } ;
194183}
0 commit comments