1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // A port of the simplistic benchmark from
13 // http://github.com/PaulKeeble/ScalaVErlangAgents
15 // I *think* it's the same, more or less.
17 // This version uses pipes with a shared send endpoint. It should have
18 // different scalability characteristics compared to the select
28 fn move_out<T>(_x: T) {}
36 fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
40 match requests.recv_opt() {
41 Some(get_count) => { responses.send(count.clone()); }
43 //println!("server: received {:?} bytes", b);
46 None => { done = true; }
50 responses.send(count);
51 //println!("server exiting");
54 fn run(args: &[~str]) {
55 let (to_parent, from_child) = channel();
56 let (to_child, from_parent) = channel();
58 let size = from_str::<uint>(args[1]).unwrap();
59 let workers = from_str::<uint>(args[2]).unwrap();
61 let start = time::precise_time_s();
62 let mut worker_results = Vec::new();
63 for _ in range(0u, workers) {
64 let to_child = to_child.clone();
65 let mut builder = task::task();
66 worker_results.push(builder.future_result());
67 builder.spawn(proc() {
68 for _ in range(0u, size / workers) {
69 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
70 to_child.send(bytes(num_bytes));
72 //println!("worker {:?} exiting", i);
76 server(&from_parent, &to_parent);
79 for r in worker_results.iter() {
83 //println!("sending stop message");
86 let result = from_child.recv();
87 let end = time::precise_time_s();
88 let elapsed = end - start;
89 print!("Count is {:?}\n", result);
90 print!("Test took {:?} seconds\n", elapsed);
91 let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
92 print!("Throughput={} per sec\n", thruput);
93 assert_eq!(result, num_bytes * size);
97 let args = os::args();
98 let args = if os::getenv("RUST_BENCH").is_some() {
99 vec!(~"", ~"1000000", ~"10000")
100 } else if args.len() <= 1u {
101 vec!(~"", ~"10000", ~"4")
106 println!("{:?}", args);