12
12
// http://shootout.alioth.debian.org/
13
13
// u64q/program.php?test=mandelbrot&lang=python3&id=2
14
14
//
15
- // takes 3 optional args:
15
+ // takes 2 optional args:
16
16
// square image size, defaults to 80_u
17
- // yield frequency, defaults to 10_u (yield every 10 spawns)
18
17
// output path, default is "" (no output), "-" means stdout
19
18
//
20
19
// in the shootout, they use 16000 as image size
21
- // yield frequency doesn't seem to have much effect
22
20
//
23
21
// writes pbm image to output path
24
22
25
- #[ legacy_modes] ;
26
-
27
23
extern mod std;
28
24
use io:: WriterUtil ;
29
25
use std:: map:: HashMap ;
@@ -51,7 +47,7 @@ impl cmplx : ops::Add<cmplx,cmplx> {
51
47
}
52
48
}
53
49
54
- type line = { i : uint , b : ~[ u8 ] } ;
50
+ struct Line { i : uint , b : ~[ u8 ] }
55
51
56
52
pure fn cabs ( x : cmplx ) -> f64
57
53
{
@@ -87,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
87
83
rv
88
84
}
89
85
90
- fn chanmb ( i : uint , size : uint , ch : oldcomm:: Chan < line > ) -> ( )
86
+ fn chanmb ( i : uint , size : uint , ch : oldcomm:: Chan < Line > ) -> ( )
91
87
{
92
88
let mut crv = ~[ ] ;
93
89
let incr = 2f64 /( size as f64 ) ;
@@ -97,22 +93,22 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<line>) -> ()
97
93
let x = cmplx { re : xincr* ( j as f64 ) - 1.5f64 , im : y} ;
98
94
crv. push ( fillbyte ( x, incr) ) ;
99
95
} ;
100
- oldcomm:: send ( ch, { i: i, b: crv} ) ;
96
+ oldcomm:: send ( ch, Line { i : i, b : move crv} ) ;
101
97
}
102
98
103
99
type devnull = { dn : int } ;
104
100
105
101
impl devnull: io:: Writer {
106
102
fn write ( _b : & [ const u8 ] ) { }
107
- fn seek ( + _i : int , + _s : io:: SeekStyle ) { }
103
+ fn seek ( _i : int , _s : io:: SeekStyle ) { }
108
104
fn tell ( ) -> uint { 0_ u}
109
105
fn flush ( ) -> int { 0 }
110
106
fn get_type ( ) -> io:: WriterType { io:: File }
111
107
}
112
108
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 )
114
110
{
115
- let p: oldcomm:: Port < line > = oldcomm:: Port ( ) ;
111
+ let p: oldcomm:: Port < Line > = oldcomm:: Port ( ) ;
116
112
let ch = oldcomm:: Chan ( & p) ;
117
113
oldcomm:: send ( writech, ch) ;
118
114
let cout: io:: Writer = match path {
@@ -164,16 +160,13 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<line>>, size: uint)
164
160
fn main ( ) {
165
161
let args = os:: args ( ) ;
166
162
let args = if os:: getenv ( ~"RUST_BENCH ") . is_some ( ) {
167
- ~[ ~"", ~"4000 ", ~" 10 " ]
163
+ ~[ ~"", ~"4000 "]
168
164
} else {
169
165
args
170
166
} ;
171
167
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
177
170
178
171
let size = if vec:: len ( args) < 2_ u { 80_ u }
179
172
else { uint:: from_str ( args[ 1 ] ) . get ( ) } ;
@@ -185,10 +178,6 @@ fn main() {
185
178
} ;
186
179
let ch = oldcomm:: recv ( writep) ;
187
180
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) } ;
193
182
} ;
194
183
}
0 commit comments