Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (93 sloc) 3.165 kb
5c3889a Eric Holk 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 Eric Holk Updating tests to use pipes.
eholk authored
7 // This version uses automatically compiled channel contracts.
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
8
9 // xfail-pretty
10
f686896 Patrick Walton test: "import" -> "use"
pcwalton authored
11 use future::future;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
12
13 use std;
f686896 Patrick Walton test: "import" -> "use"
pcwalton authored
14 use std::time;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
15
f686896 Patrick Walton test: "import" -> "use"
pcwalton authored
16 use pipes::recv;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
17
77e83d8 Paul Stansifer Change calls of `proto!` to use parens.
paulstansifer authored
18 proto! ring (
7b03832 Eric Holk Updating tests to use pipes.
eholk authored
19 num:send {
20 num(uint) -> num
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
21 }
77e83d8 Paul Stansifer Change calls of `proto!` to use parens.
paulstansifer authored
22 )
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
23
24 fn macros() {
25 #macro[
c5437c0 Brian Anderson Fix failing tests
brson authored
26 [#move_out[x],
5c3889a Eric Holk 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) {
8337fa1 Brian Anderson Camel case the option type
brson authored
35 let mut num_chan <- Some(num_chan);
36 let mut num_port <- Some(num_port);
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
37 // Send/Receive lots of messages.
a4838c9 Eric Holk Enabling pipes for all stages, and updating closure syntax.
eholk authored
38 for uint::range(0u, count) |j| {
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
39 //error!("task %?, iter %?", i, j);
8337fa1 Brian Anderson Camel case the option type
brson authored
40 let mut num_chan2 = None;
41 let mut num_port2 = None;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
42 num_chan2 <-> num_chan;
43 num_port2 <-> num_port;
8337fa1 Brian Anderson Camel case the option type
brson authored
44 num_chan = Some(ring::client::num(option::unwrap(num_chan2), i * j));
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
45 let port = option::unwrap(num_port2);
ecaf9e3 Brian Anderson Convert alt to match. Stop parsing alt
brson authored
46 match recv(port) {
025d866 Brian Anderson Switch alts to use arrows
brson authored
47 ring::num(_n, p) => {
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
48 //log(error, _n);
8337fa1 Brian Anderson Camel case the option type
brson authored
49 num_port = Some(move_out!(p));
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
50 }
51 }
52 };
53 }
54
92743dc Michael J. Sullivan 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 Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
58 } else if args.len() <= 1u {
92743dc Michael J. Sullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
59 ~[~"", ~"100", ~"1000"]
5c3889a Eric Holk 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();
8337fa1 Brian Anderson Camel case the option type
brson authored
68 let mut num_chan = Some(num_chan);
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
69
70 let start = time::precise_time_s();
71
72 // create the ring
1c62f5f Michael J. Sullivan Get rid of all of the remaining /~s in the code base.
msullivan authored
73 let mut futures = ~[];
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
74
a4838c9 Eric Holk Enabling pipes for all stages, and updating closure syntax.
eholk authored
75 for uint::range(1u, num_tasks) |i| {
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
76 //error!("spawning %?", i);
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
77 let (new_chan, num_port) = ring::init();
8337fa1 Brian Anderson Camel case the option type
brson authored
78 let num_chan2 = ~mut None;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
79 *num_chan2 <-> num_chan;
8337fa1 Brian Anderson Camel case the option type
brson authored
80 let num_port = ~mut Some(num_port);
8e86cd0 Jeff Olson test: bunch of test cleanup from sendable_futures change
olsonjeffery authored
81 let new_future = do future::spawn
82 |move num_chan2, move num_port| {
8337fa1 Brian Anderson Camel case the option type
brson authored
83 let mut num_chan = None;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
84 num_chan <-> *num_chan2;
8337fa1 Brian Anderson Camel case the option type
brson authored
85 let mut num_port1 = None;
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
86 num_port1 <-> *num_port;
87 thread_ring(i, msg_per_task,
88 option::unwrap(num_chan),
89 option::unwrap(num_port1))
8e86cd0 Jeff Olson test: bunch of test cleanup from sendable_futures change
olsonjeffery authored
90 };
91 vec::push(futures, new_future);
8337fa1 Brian Anderson Camel case the option type
brson authored
92 num_chan = Some(new_chan);
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
93 };
94
95 // do our iteration
96 thread_ring(0u, msg_per_task, option::unwrap(num_chan), num_port);
97
98 // synchronize
9600744 Graydon Hoare fix more fallout from future de-mode-ing.
graydon authored
99 for futures.each |f| { future::get(&f) };
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
100
101 let stop = time::precise_time_s();
102
103 // all done, report stats.
104 let num_msgs = num_tasks * msg_per_task;
105 let elapsed = (stop - start);
106 let rate = (num_msgs as float) / elapsed;
107
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
108 io::println(fmt!("Sent %? messages in %? seconds",
109 num_msgs, elapsed));
110 io::println(fmt!(" %? messages / second", rate));
111 io::println(fmt!(" %? μs / message", 1000000. / rate));
5c3889a Eric Holk Contracts work well enough to do the message ring benchmark, and it's re...
eholk authored
112 }
Something went wrong with that request. Please try again.