Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (91 sloc) 3.111 kb
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
1 // This test creates a bunch of tasks that simultaneously send to each
2 // other in a ring. The messages should all be basically
3 // independent. It's designed to hammer the global kernel lock, so
4 // that things will look really good once we get that lock out of the
5 // message path.
6
7b03832 @eholk Updating tests to use pipes.
eholk authored
7 // This version uses automatically compiled channel contracts.
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
8
9 // xfail-pretty
10
11 import future::future;
12
13 use std;
14 import std::time;
15
7b03832 @eholk Updating tests to use pipes.
eholk authored
16 import pipes::recv;
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
17
7b03832 @eholk Updating tests to use pipes.
eholk authored
18 proto! ring {
19 num:send {
20 num(uint) -> num
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
21 }
22 }
23
24 fn macros() {
25 #macro[
c5437c0 @brson Fix failing tests
brson authored
26 [#move_out[x],
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
27 unsafe { let y <- *ptr::addr_of(x); y }]
28 ];
29 }
30
31 fn thread_ring(i: uint,
32 count: uint,
33 +num_chan: ring::client::num,
34 +num_port: ring::server::num) {
35 let mut num_chan <- some(num_chan);
36 let mut num_port <- some(num_port);
37 // Send/Receive lots of messages.
a4838c9 @eholk Enabling pipes for all stages, and updating closure syntax.
eholk authored
38 for uint::range(0u, count) |j| {
a9cc506 @paulstansifer Change syntax extension syntax: `#m[...]` -> `m!{...}`.
paulstansifer authored
39 //error!{"task %?, iter %?", i, j};
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
40 let mut num_chan2 = none;
41 let mut num_port2 = none;
42 num_chan2 <-> num_chan;
43 num_port2 <-> num_port;
44 num_chan = some(ring::client::num(option::unwrap(num_chan2), i * j));
45 let port = option::unwrap(num_port2);
594d9a0 @eholk Use protocol compiler in future.rs. Also split recv into recv and try_re...
eholk authored
46 alt recv(port) {
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
47 ring::num(_n, p) {
48 //log(error, _n);
c5437c0 @brson Fix failing tests
brson authored
49 num_port = some(move_out!{p});
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
50 }
51 }
52 };
53 }
54
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
55 fn main(args: ~[~str]) {
56 let args = if os::getenv(~"RUST_BENCH").is_some() {
57 ~[~"", ~"100", ~"10000"]
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
58 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
59 ~[~"", ~"100", ~"1000"]
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
60 } else {
61 copy args
62 };
63
64 let num_tasks = option::get(uint::from_str(args[1]));
65 let msg_per_task = option::get(uint::from_str(args[2]));
66
67 let (num_chan, num_port) = ring::init();
68 let mut num_chan = some(num_chan);
69
70 let start = time::precise_time_s();
71
72 // create the ring
1c62f5f @msullivan Get rid of all of the remaining /~s in the code base.
msullivan authored
73 let mut futures = ~[];
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
74
a4838c9 @eholk Enabling pipes for all stages, and updating closure syntax.
eholk authored
75 for uint::range(1u, num_tasks) |i| {
a9cc506 @paulstansifer Change syntax extension syntax: `#m[...]` -> `m!{...}`.
paulstansifer authored
76 //error!{"spawning %?", i};
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
77 let (new_chan, num_port) = ring::init();
78 let num_chan2 = ~mut none;
79 *num_chan2 <-> num_chan;
80 let num_port = ~mut some(num_port);
1c62f5f @msullivan Get rid of all of the remaining /~s in the code base.
msullivan authored
81 futures += ~[future::spawn(|move num_chan2, move num_port| {
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
82 let mut num_chan = none;
83 num_chan <-> *num_chan2;
84 let mut num_port1 = none;
85 num_port1 <-> *num_port;
86 thread_ring(i, msg_per_task,
87 option::unwrap(num_chan),
88 option::unwrap(num_port1))
1c62f5f @msullivan Get rid of all of the remaining /~s in the code base.
msullivan authored
89 })];
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
90 num_chan = some(new_chan);
91 };
92
93 // do our iteration
94 thread_ring(0u, msg_per_task, option::unwrap(num_chan), num_port);
95
96 // synchronize
a787f40 @eholk Select on pipes.
eholk authored
97 for futures.each |f| { future::get(f) };
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
98
99 let stop = time::precise_time_s();
100
101 // all done, report stats.
102 let num_msgs = num_tasks * msg_per_task;
103 let elapsed = (stop - start);
104 let rate = (num_msgs as float) / elapsed;
105
a9cc506 @paulstansifer Change syntax extension syntax: `#m[...]` -> `m!{...}`.
paulstansifer authored
106 io::println(fmt!{"Sent %? messages in %? seconds",
107 num_msgs, elapsed});
108 io::println(fmt!{" %? messages / second", rate});
109 io::println(fmt!{" %? μs / message", 1000000. / rate});
5c3889a @eholk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
110 }
Something went wrong with that request. Please try again.