Skip to content

Commit 5b4d330

Browse files
committed
---
yaml --- r: 13556 b: refs/heads/master c: 9ee1480 h: refs/heads/master v: v3
1 parent 3519d66 commit 5b4d330

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f648affeaa9b24af8183842fa5aea31479dd6310
2+
refs/heads/master: 9ee1480fd19a4a98e3c2ce6076f4dc6eff63a620
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/test/bench/msgsend-ring.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
7+
import comm::*;
8+
import future::future;
9+
10+
use std;
11+
import std::time;
12+
13+
fn thread_ring(i: uint,
14+
count: uint,
15+
num_chan: comm::chan<uint>,
16+
num_port: comm::port<uint>) {
17+
// Send/Receive lots of messages.
18+
for uint::range(0u, count) {|j|
19+
num_chan.send(i * j);
20+
num_port.recv();
21+
};
22+
}
23+
24+
fn main(args: [str]) {
25+
let args = if os::getenv("RUST_BENCH").is_some() {
26+
["", "100", "10000"]
27+
} else if args.len() <= 1u {
28+
["", "100", "1000"]
29+
} else {
30+
args
31+
};
32+
33+
let num_tasks = option::get(uint::from_str(args[1]));
34+
let msg_per_task = option::get(uint::from_str(args[2]));
35+
36+
let num_port = port();
37+
let mut num_chan = chan(num_port);
38+
39+
let start = time::precise_time_s();
40+
41+
// create the ring
42+
let mut futures = [];
43+
44+
for uint::range(1u, num_tasks) {|i|
45+
let get_chan = port();
46+
let get_chan_chan = chan(get_chan);
47+
48+
futures += [future::spawn {|copy num_chan, move get_chan_chan|
49+
let p = port();
50+
get_chan_chan.send(chan(p));
51+
thread_ring(i, msg_per_task, num_chan, p)
52+
}];
53+
54+
num_chan = get_chan.recv();
55+
};
56+
57+
// do our iteration
58+
thread_ring(0u, msg_per_task, num_chan, num_port);
59+
60+
// synchronize
61+
for futures.each {|f| f.get() };
62+
63+
let stop = time::precise_time_s();
64+
65+
// all done, report stats.
66+
let num_msgs = num_tasks * msg_per_task;
67+
let elapsed = (stop - start);
68+
let rate = (num_msgs as float) / elapsed;
69+
70+
io::println(#fmt("Sent %? messages in %? seconds",
71+
num_msgs, elapsed));
72+
io::println(#fmt(" %? messages / second", rate));
73+
io::println(#fmt(" %? μs / message", 1000000. / rate));
74+
}

0 commit comments

Comments
 (0)