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.
24 fn move_out<T>(_x: T) {}
32 fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
33 let mut count: uint = 0;
36 match requests.recv_opt() {
37 Ok(get_count) => { responses.send(count.clone()); }
39 //println!("server: received {:?} bytes", b);
42 Err(..) => { done = true; }
46 responses.send(count);
47 //println!("server exiting");
50 fn run(args: &[String]) {
51 let (to_parent, from_child) = channel();
53 let size = from_str::<uint>(args[1].as_slice()).unwrap();
54 let workers = from_str::<uint>(args[2].as_slice()).unwrap();
56 let start = time::precise_time_s();
57 let mut worker_results = Vec::new();
58 let from_parent = if workers == 1 {
59 let (to_child, from_parent) = channel();
60 worker_results.push(task::try_future(proc() {
61 for _ in range(0u, size / workers) {
62 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
63 to_child.send(bytes(num_bytes));
65 //println!("worker {:?} exiting", i);
69 let (to_child, from_parent) = channel();
70 for _ in range(0u, workers) {
71 let to_child = to_child.clone();
72 worker_results.push(task::try_future(proc() {
73 for _ in range(0u, size / workers) {
74 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
75 to_child.send(bytes(num_bytes));
77 //println!("worker {:?} exiting", i);
83 server(&from_parent, &to_parent);
86 for r in worker_results.move_iter() {
90 //println!("sending stop message");
91 //to_child.send(stop);
93 let result = from_child.recv();
94 let end = time::precise_time_s();
95 let elapsed = end - start;
96 print!("Count is {:?}\n", result);
97 print!("Test took {:?} seconds\n", elapsed);
98 let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
99 print!("Throughput={} per sec\n", thruput);
100 assert_eq!(result, num_bytes * size);
104 let args = os::args();
105 let args = if os::getenv("RUST_BENCH").is_some() {
106 vec!("".to_string(), "1000000".to_string(), "8".to_string())
107 } else if args.len() <= 1u {
108 vec!("".to_string(), "10000".to_string(), "4".to_string())
110 args.clone().move_iter().map(|x| x.to_string()).collect()
113 println!("{:?}", args);
114 run(args.as_slice());