Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (124 sloc) 3.424 kb
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
1 // Compare bounded and unbounded protocol performance.
2
3 // xfail-pretty
4
ea01ee2 @brson Convert 'use' to 'extern mod'. Remove old 'use' syntax
brson authored
5 extern mod std;
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
6
f686896 @pcwalton test: "import" -> "use"
pcwalton authored
7 use pipes::{spawn_service, recv};
8 use std::time::precise_time_s;
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
9
77e83d8 @paulstansifer Change calls of `proto!` to use parens.
paulstansifer authored
10 proto! pingpong (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
11 ping: send {
12 ping -> pong
13 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
14
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
15 pong: recv {
16 pong -> ping
17 }
77e83d8 @paulstansifer Change calls of `proto!` to use parens.
paulstansifer authored
18 )
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
19
77e83d8 @paulstansifer Change calls of `proto!` to use parens.
paulstansifer authored
20 proto! pingpong_unbounded (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
21 ping: send {
22 ping -> pong
23 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
24
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
25 pong: recv {
26 pong -> ping
27 }
28
29 you_will_never_catch_me: send {
30 never_ever_ever -> you_will_never_catch_me
31 }
77e83d8 @paulstansifer Change calls of `proto!` to use parens.
paulstansifer authored
32 )
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
33
34 // This stuff should go in libcore::pipes
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
35 macro_rules! move_it (
b183204 @catamorphism Move over to calling ptr::addr_of
catamorphism authored
36 { $x:expr } => { let t <- *ptr::addr_of(&($x)); t }
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
37 )
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
38
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
39 macro_rules! follow (
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
40 {
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
41 $($message:path($($x: ident),+) -> $next:ident $e:expr)+
42 } => (
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
43 |m| match move m {
8337fa1 @brson Camel case the option type
brson authored
44 $(Some($message($($x,)* next)) => {
c973732 @eholk Enabling pingpong benchmark.
eholk authored
45 // FIXME (#2329) use regular move here once move out of
46 // enums is supported.
47 let $next = unsafe { move_it!(next) };
48 $e })+
49 _ => { fail }
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
50 }
51 );
52
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
53 {
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
54 $($message:path -> $next:ident $e:expr)+
55 } => (
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
56 |m| match move m {
8337fa1 @brson Camel case the option type
brson authored
57 $(Some($message(next)) => {
c973732 @eholk Enabling pingpong benchmark.
eholk authored
58 // FIXME (#2329) use regular move here once move out of
59 // enums is supported.
60 let $next = unsafe { move_it!(next) };
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
61 $e })+
c973732 @eholk Enabling pingpong benchmark.
eholk authored
62 _ => { fail }
63 }
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
64 )
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
65 )
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
66
3bd1f32 @brson Convert all kind bounds to camel case. Remove send, owned keywords.
brson authored
67 fn switch<T: Send, Tb: Send, U>(+endp: pipes::RecvPacketBuffered<T, Tb>,
ba3eebd @nikomatsakis Make it illegal to use modes in a fn signature with providing
nikomatsakis authored
68 f: fn(+v: Option<T>) -> U) -> U {
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
69 f(pipes::try_recv(endp))
70 }
71
72 // Here's the benchmark
73
74 fn bounded(count: uint) {
298eb8c @brson Convert 'import' to 'use'. Remove 'import' keyword.
brson authored
75 use pingpong::*;
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
76
77 let mut ch = do spawn_service(init) |ch| {
78 let mut count = count;
79 let mut ch = ch;
80 while count > 0 {
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
81 ch = switch(ch, follow! (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
82 ping -> next { server::pong(next) }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
83 ));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
84
85 count -= 1;
86 }
87 };
88
89 let mut count = count;
90 while count > 0 {
91 let ch_ = client::ping(ch);
92
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
93 ch = switch(ch_, follow! (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
94 pong -> next { next }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
95 ));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
96
97 count -= 1;
98 }
99 }
100
101 fn unbounded(count: uint) {
298eb8c @brson Convert 'import' to 'use'. Remove 'import' keyword.
brson authored
102 use pingpong_unbounded::*;
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
103
104 let mut ch = do spawn_service(init) |ch| {
105 let mut count = count;
106 let mut ch = ch;
107 while count > 0 {
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
108 ch = switch(ch, follow! (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
109 ping -> next { server::pong(next) }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
110 ));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
111
112 count -= 1;
113 }
114 };
115
116 let mut count = count;
117 while count > 0 {
118 let ch_ = client::ping(ch);
119
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
120 ch = switch(ch_, follow! (
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
121 pong -> next { next }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
122 ));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
123
124 count -= 1;
125 }
126 }
127
128 fn timeit(f: fn()) -> float {
129 let start = precise_time_s();
130 f();
131 let stop = precise_time_s();
132 stop - start
133 }
134
135 fn main() {
c973732 @eholk Enabling pingpong benchmark.
eholk authored
136 let count = if os::getenv(~"RUST_BENCH").is_some() {
137 250000
138 } else {
139 100
140 };
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
141 let bounded = do timeit { bounded(count) };
142 let unbounded = do timeit { unbounded(count) };
143
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
144 io::println(fmt!("count: %?\n", count));
145 io::println(fmt!("bounded: %? s\t(%? μs/message)",
146 bounded, bounded * 1000000. / (count as float)));
147 io::println(fmt!("unbounded: %? s\t(%? μs/message)",
148 unbounded, unbounded * 1000000. / (count as float)));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
149
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
150 io::println(fmt!("\n\
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
151 bounded is %?%% faster",
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
152 (unbounded - bounded) / bounded * 100.));
3557616 @eholk Added a benchmark of bounded vs unbounded. Bounded is 8-12% faster. T…
eholk authored
153 }
Something went wrong with that request. Please try again.