19
19
20
20
use std:: sync:: mpsc:: channel;
21
21
use std:: os;
22
- use std:: str:: from_str;
23
22
use std:: thread:: Thread ;
24
- use std:: uint;
25
23
26
24
// This is a simple bench that creates M pairs of tasks. These
27
25
// tasks ping-pong back and forth over a pair of streams. This is a
@@ -32,24 +30,24 @@ fn ping_pong_bench(n: uint, m: uint) {
32
30
33
31
// Create pairs of tasks that pingpong back and forth.
34
32
fn run_pair ( n : uint ) {
35
- // Create a stream A->B
36
- let ( atx, arx) = channel :: < ( ) > ( ) ;
37
- // Create a stream B->A
38
- let ( btx, brx) = channel :: < ( ) > ( ) ;
33
+ // Create a channel: A->B
34
+ let ( atx, arx) = channel ( ) ;
35
+ // Create a channel: B->A
36
+ let ( btx, brx) = channel ( ) ;
39
37
40
38
Thread :: spawn ( move || {
41
39
let ( tx, rx) = ( atx, brx) ;
42
40
for _ in range ( 0 , n) {
43
- tx. send ( ( ) ) ;
44
- rx. recv ( ) ;
41
+ tx. send ( ( ) ) . unwrap ( ) ;
42
+ rx. recv ( ) . unwrap ( ) ;
45
43
}
46
44
} ) . detach ( ) ;
47
45
48
46
Thread :: spawn ( move || {
49
47
let ( tx, rx) = ( btx, arx) ;
50
48
for _ in range ( 0 , n) {
51
- rx. recv ( ) ;
52
- tx. send ( ( ) ) ;
49
+ rx. recv ( ) . unwrap ( ) ;
50
+ tx. send ( ( ) ) . unwrap ( ) ;
53
51
}
54
52
} ) . detach ( ) ;
55
53
}
@@ -66,13 +64,13 @@ fn main() {
66
64
let args = os:: args ( ) ;
67
65
let args = args. as_slice ( ) ;
68
66
let n = if args. len ( ) == 3 {
69
- from_str :: < uint > ( args [ 1 ] . as_slice ( ) ) . unwrap ( )
67
+ args [ 1 ] . parse :: < uint > ( ) . unwrap ( )
70
68
} else {
71
69
10000
72
70
} ;
73
71
74
72
let m = if args. len ( ) == 3 {
75
- from_str :: < uint > ( args [ 2 ] . as_slice ( ) ) . unwrap ( )
73
+ args [ 2 ] . parse :: < uint > ( ) . unwrap ( )
76
74
} else {
77
75
4
78
76
} ;
0 commit comments