Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (86 sloc) 2.77 kb
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
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 port s...
eholk authored
13 use std;
1125831 @brson Convert more core types to camel case
brson authored
14 import io::Writer;
15 import io::WriterUtil;
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
16
cfbc7cb @brson Convert core::pipes to camel case
brson authored
17 import pipes::{Port, Chan, SharedChan};
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
18
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
19 macro_rules! move_out (
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
20 { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
38891b9 @paulstansifer Update invocation syntax for `macro_rules!`
paulstansifer authored
21 )
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
22
23 enum request {
24 get_count,
25 bytes(uint),
26 stop
27 }
28
cfbc7cb @brson Convert core::pipes to camel case
brson authored
29 fn server(requests: Port<request>, responses: pipes::Chan<uint>) {
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
30 let mut count = 0u;
31 let mut done = false;
32 while !done {
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
33 match requests.try_recv() {
8337fa1 @brson Camel case the option type
brson authored
34 Some(get_count) => { responses.send(copy count); }
35 Some(bytes(b)) => {
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
36 //error!("server: received %? bytes", b);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
37 count += b;
38 }
8337fa1 @brson Camel case the option type
brson authored
39 None => { done = true; }
025d866 @brson Switch alts to use arrows
brson authored
40 _ => { }
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
41 }
42 }
43 responses.send(count);
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
44 //error!("server exiting");
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
45 }
46
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
47 fn run(args: &[~str]) {
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
48 let (to_parent, from_child) = pipes::stream();
49 let (to_child, from_parent) = pipes::stream();
50
5f57588 @eholk Update the rock-paper-scissors example in the tutorial, and rename some ...
eholk authored
51 let to_child = SharedChan(to_child);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
52
53 let size = option::get(uint::from_str(args[1]));
54 let workers = option::get(uint::from_str(args[2]));
55 let num_bytes = 100;
56 let start = std::time::precise_time_s();
57 let mut worker_results = ~[];
58 for uint::range(0u, workers) |i| {
59 let to_child = to_child.clone();
18ac4a8 @bblum Change task().future_result's argument mode
bblum authored
60 do task::task().future_result(|+r| {
b30a58a @bblum Convert bench and run-pass tests to new task_builder interface
bblum authored
61 vec::push(worker_results, r);
62 }).spawn {
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
63 for uint::range(0u, size / workers) |_i| {
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
64 //error!("worker %?: sending %? bytes", i, num_bytes);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
65 to_child.send(bytes(num_bytes));
66 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
67 //error!("worker %? exiting", i);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
68 };
69 }
70 do task::spawn {
71 server(from_parent, to_parent);
72 }
73
9600744 @graydon fix more fallout from future de-mode-ing.
graydon authored
74 vec::iter(worker_results, |r| { future::get(&r); } );
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
75 //error!("sending stop message");
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
76 to_child.send(stop);
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
77 move_out!(to_child);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
78 let result = from_child.recv();
79 let end = std::time::precise_time_s();
80 let elapsed = end - start;
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
81 io::stdout().write_str(fmt!("Count is %?\n", result));
82 io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed));
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
83 let thruput = ((size / workers * workers) as float) / (elapsed as float);
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
84 io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
85 assert result == num_bytes * size;
86 }
87
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
88 fn main(args: ~[~str]) {
89 let args = if os::getenv(~"RUST_BENCH").is_some() {
90 ~[~"", ~"1000000", ~"10000"]
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
91 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
92 ~[~"", ~"10000", ~"4"]
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
93 } else {
94 copy args
95 };
96
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
97 debug!("%?", args);
ba10819 @eholk Added a message send that uses shared chans. They are slower than port s...
eholk authored
98 run(args);
99 }
Something went wrong with that request. Please try again.