Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (87 sloc) 2.771 kB
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
1 // A port of the simplistic benchmark from
2 //
3 // http://github.com/PaulKeeble/ScalaVErlangAgents
4 //
5 // I *think* it's the same, more or less.
6
7 // This version uses pipes with a shared send endpoint. It should have
8 // different scalability characteristics compared to the select
9 // version.
10
05543fd @eholk Make tests pass
eholk authored
11 // xfail-pretty
12
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
13 use std;
14 import io::writer;
15 import io::writer_util;
16
17 import arc::methods;
fec8059 @eholk Move port_set and shared_chan into core.
eholk authored
18 import pipes::{port, chan, shared_chan};
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
19
20 macro_rules! move {
21 { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
22 }
23
24 enum request {
25 get_count,
26 bytes(uint),
27 stop
28 }
29
30 fn server(requests: port<request>, responses: pipes::chan<uint>) {
31 let mut count = 0u;
32 let mut done = false;
33 while !done {
34 alt requests.try_recv() {
35 some(get_count) { responses.send(copy count); }
36 some(bytes(b)) {
37 //#error("server: received %? bytes", b);
38 count += b;
39 }
40 none { done = true; }
41 _ { }
42 }
43 }
44 responses.send(count);
45 //#error("server exiting");
46 }
47
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
48 fn run(args: &[~str]) {
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
49 let (to_parent, from_child) = pipes::stream();
50 let (to_child, from_parent) = pipes::stream();
51
52 let to_child = shared_chan(to_child);
53
54 let size = option::get(uint::from_str(args[1]));
55 let workers = option::get(uint::from_str(args[2]));
56 let num_bytes = 100;
57 let start = std::time::precise_time_s();
58 let mut worker_results = ~[];
59 for uint::range(0u, workers) |i| {
60 let to_child = to_child.clone();
b30a58a @bblum Convert bench and run-pass tests to new task_builder interface
bblum authored
61 do task::task().future_result(|-r| {
62 vec::push(worker_results, r);
63 }).spawn {
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
64 for uint::range(0u, size / workers) |_i| {
65 //#error("worker %?: sending %? bytes", i, num_bytes);
66 to_child.send(bytes(num_bytes));
67 }
68 //#error("worker %? exiting", i);
69 };
70 }
71 do task::spawn {
72 server(from_parent, to_parent);
73 }
74
75 vec::iter(worker_results, |r| { future::get(r); } );
76 //#error("sending stop message");
77 to_child.send(stop);
78 move!{to_child};
79 let result = from_child.recv();
80 let end = std::time::precise_time_s();
81 let elapsed = end - start;
82 io::stdout().write_str(#fmt("Count is %?\n", result));
83 io::stdout().write_str(#fmt("Test took %? seconds\n", elapsed));
84 let thruput = ((size / workers * workers) as float) / (elapsed as float);
85 io::stdout().write_str(#fmt("Throughput=%f per sec\n", thruput));
86 assert result == num_bytes * size;
87 }
88
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
89 fn main(args: ~[~str]) {
90 let args = if os::getenv(~"RUST_BENCH").is_some() {
91 ~[~"", ~"1000000", ~"10000"]
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
92 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
93 ~[~"", ~"10000", ~"4"]
ba10819 @eholk Added a message send that uses shared chans. They are slower than por…
eholk authored
94 } else {
95 copy args
96 };
97
98 #debug("%?", args);
99 run(args);
100 }
Something went wrong with that request. Please try again.