Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (60 sloc) 2.099 kb
9ee1480 @eholk Another benchmark
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
f686896 @pcwalton test: "import" -> "use"
pcwalton authored
7 use comm::*;
8 use future::future;
9ee1480 @eholk Another benchmark
eholk authored
9
ea01ee2 @brson Convert 'use' to 'extern mod'. Remove old 'use' syntax
brson authored
10 extern mod std;
f686896 @pcwalton test: "import" -> "use"
pcwalton authored
11 use std::time;
9ee1480 @eholk Another benchmark
eholk authored
12
13 fn thread_ring(i: uint,
14 count: uint,
9c6890f @brson Convert more core types to camel case
brson authored
15 num_chan: comm::Chan<uint>,
16 num_port: comm::Port<uint>) {
9ee1480 @eholk Another benchmark
eholk authored
17 // Send/Receive lots of messages.
d1fc2b5 @brson Convert to new closure syntax
brson authored
18 for uint::range(0u, count) |j| {
9ee1480 @eholk Another benchmark
eholk authored
19 num_chan.send(i * j);
20 num_port.recv();
21 };
22 }
23
267ab11 @nikomatsakis use + mode for (almost) everything when not using legacy modes
nikomatsakis authored
24 fn main(++args: ~[~str]) {
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
25 let args = if os::getenv(~"RUST_BENCH").is_some() {
26 ~[~"", ~"100", ~"10000"]
9ee1480 @eholk Another benchmark
eholk authored
27 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
28 ~[~"", ~"100", ~"1000"]
9ee1480 @eholk Another benchmark
eholk authored
29 } else {
30 args
31 };
32
4a78f9b @brson core: Demode option
brson authored
33 let num_tasks = uint::from_str(args[1]).get();
34 let msg_per_task = uint::from_str(args[2]).get();
9ee1480 @eholk Another benchmark
eholk authored
35
161a82e @brson Camel case various core constructors
brson authored
36 let num_port = Port();
37 let mut num_chan = Chan(num_port);
9ee1480 @eholk Another benchmark
eholk authored
38
39 let start = time::precise_time_s();
40
41 // create the ring
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
42 let mut futures = ~[];
9ee1480 @eholk Another benchmark
eholk authored
43
d1fc2b5 @brson Convert to new closure syntax
brson authored
44 for uint::range(1u, num_tasks) |i| {
161a82e @brson Camel case various core constructors
brson authored
45 let get_chan = Port();
46 let get_chan_chan = Chan(get_chan);
9ee1480 @eholk Another benchmark
eholk authored
47
8e86cd0 @olsonjeffery test: bunch of test cleanup from sendable_futures change
olsonjeffery authored
48 let new_future = do future::spawn
49 |copy num_chan, move get_chan_chan| {
161a82e @brson Camel case various core constructors
brson authored
50 let p = Port();
51 get_chan_chan.send(Chan(p));
9ee1480 @eholk Another benchmark
eholk authored
52 thread_ring(i, msg_per_task, num_chan, p)
8e86cd0 @olsonjeffery test: bunch of test cleanup from sendable_futures change
olsonjeffery authored
53 };
67a8e71 @nikomatsakis Demode vec::push (and convert to method)
nikomatsakis authored
54 futures.push(new_future);
9ee1480 @eholk Another benchmark
eholk authored
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
d1fc2b5 @brson Convert to new closure syntax
brson authored
63 for futures.each |f| { f.get() };
9ee1480 @eholk Another benchmark
eholk authored
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
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
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));
9ee1480 @eholk Another benchmark
eholk authored
76 }
Something went wrong with that request. Please try again.