Skip to content

Commit 28e1a4d

Browse files
committed
---
yaml --- r: 13630 b: refs/heads/master c: 40559ea h: refs/heads/master v: v3
1 parent 928f7da commit 28e1a4d

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-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: dc3862bf58297b75a0e3d4dfdf1f66b56f51dd1d
2+
refs/heads/master: 40559ea83961df06c82f76c333ce4c9604f12449
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 newcomm::*;
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: chan<uint>,
16+
num_port: 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+
let num_chan = num_chan.clone();
49+
futures += [future::spawn {|move num_chan, move get_chan_chan|
50+
let p = port();
51+
get_chan_chan.send(chan(p));
52+
thread_ring(i, msg_per_task, num_chan, p)
53+
}];
54+
}
55+
56+
num_chan = get_chan.recv();
57+
};
58+
59+
// do our iteration
60+
thread_ring(0u, msg_per_task, num_chan, num_port);
61+
62+
// synchronize
63+
for futures.each {|f| f.get() };
64+
65+
let stop = time::precise_time_s();
66+
67+
// all done, report stats.
68+
let num_msgs = num_tasks * msg_per_task;
69+
let elapsed = (stop - start);
70+
let rate = (num_msgs as float) / elapsed;
71+
72+
io::println(#fmt("Sent %? messages in %? seconds",
73+
num_msgs, elapsed));
74+
io::println(#fmt(" %? messages / second", rate));
75+
io::println(#fmt(" %? μs / message", 1000000. / rate));
76+
}

0 commit comments

Comments
 (0)