summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorEric Holk <eric.holk@gmail.com>2012-06-18 09:47:39 -0700
committerEric Holk <eric.holk@gmail.com>2012-06-19 10:31:12 -0700
commit9ee1480fd19a4a98e3c2ce6076f4dc6eff63a620 (patch)
tree2f0c656d1a36d26b7536fee75c8742c8d9f47c23 /src/test
parentf648affeaa9b24af8183842fa5aea31479dd6310 (diff)
downloadrust-9ee1480fd19a4a98e3c2ce6076f4dc6eff63a620.tar.gz
rust-9ee1480fd19a4a98e3c2ce6076f4dc6eff63a620.zip
Another benchmark
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bench/msgsend-ring.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/bench/msgsend-ring.rs b/src/test/bench/msgsend-ring.rs
new file mode 100644
index 00000000000..442b6e62dd1
--- /dev/null
+++ b/src/test/bench/msgsend-ring.rs
@@ -0,0 +1,74 @@
+// This test creates a bunch of tasks that simultaneously send to each
+// other in a ring. The messages should all be basically
+// independent. It's designed to hammer the global kernel lock, so
+// that things will look really good once we get that lock out of the
+// message path.
+
+import comm::*;
+import future::future;
+
+use std;
+import std::time;
+
+fn thread_ring(i: uint,
+               count: uint,
+               num_chan: comm::chan<uint>,
+               num_port: comm::port<uint>) {
+    // Send/Receive lots of messages.
+    for uint::range(0u, count) {|j|
+        num_chan.send(i * j);
+        num_port.recv();
+    };
+}
+
+fn main(args: [str]) {
+    let args = if os::getenv("RUST_BENCH").is_some() {
+        ["", "100", "10000"]
+    } else if args.len() <= 1u {
+        ["", "100", "1000"]
+    } else {
+        args
+    };        
+
+    let num_tasks = option::get(uint::from_str(args[1]));
+    let msg_per_task = option::get(uint::from_str(args[2]));
+
+    let num_port = port();
+    let mut num_chan = chan(num_port);
+
+    let start = time::precise_time_s();
+
+    // create the ring
+    let mut futures = [];
+
+    for uint::range(1u, num_tasks) {|i|
+        let get_chan = port();
+        let get_chan_chan = chan(get_chan);
+
+        futures += [future::spawn {|copy num_chan, move get_chan_chan|
+            let p = port();
+            get_chan_chan.send(chan(p));
+            thread_ring(i, msg_per_task, num_chan,  p)
+        }];
+        
+        num_chan = get_chan.recv();
+    };
+
+    // do our iteration
+    thread_ring(0u, msg_per_task, num_chan, num_port);
+
+    // synchronize
+    for futures.each {|f| f.get() };
+
+    let stop = time::precise_time_s();
+
+    // all done, report stats.
+    let num_msgs = num_tasks * msg_per_task;
+    let elapsed = (stop - start);
+    let rate = (num_msgs as float) / elapsed;
+
+    io::println(#fmt("Sent %? messages in %? seconds",
+                     num_msgs, elapsed));
+    io::println(#fmt("  %? messages / second", rate));
+    io::println(#fmt("  %? μs / message", 1000000. / rate));
+}