Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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