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.
23 fn move_out<T>(_x: T) {}
31 fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
32 let mut count: uint = 0;
35 match requests.recv_opt() {
36 Ok(get_count) => { responses.send(count.clone()); }
38 //println!("server: received {:?} bytes", b);
41 Err(..) => { done = true; }
45 responses.send(count);
46 //println!("server exiting");
49 fn run(args: &[~str]) {
50 let (to_parent, from_child) = channel();
52 let size = from_str::<uint>(args[1]).unwrap();
53 let workers = from_str::<uint>(args[2]).unwrap();
55 let start = time::precise_time_s();
56 let mut worker_results = Vec::new();
57 let from_parent = if workers == 1 {
58 let (to_child, from_parent) = channel();
59 let mut builder = task::task();
60 worker_results.push(builder.future_result());
61 builder.spawn(proc() {
62 for _ in range(0u, size / workers) {
63 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
64 to_child.send(bytes(num_bytes));
66 //println!("worker {:?} exiting", i);
70 let (to_child, from_parent) = channel();
71 for _ in range(0u, workers) {
72 let to_child = to_child.clone();
73 let mut builder = task::task();
74 worker_results.push(builder.future_result());
75 builder.spawn(proc() {
76 for _ in range(0u, size / workers) {
77 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
78 to_child.send(bytes(num_bytes));
80 //println!("worker {:?} exiting", i);
86 server(&from_parent, &to_parent);
89 for r in worker_results.iter() {
93 //println!("sending stop message");
94 //to_child.send(stop);
96 let result = from_child.recv();
97 let end = time::precise_time_s();
98 let elapsed = end - start;
99 print!("Count is {:?}\n", result);
100 print!("Test took {:?} seconds\n", elapsed);
101 let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
102 print!("Throughput={} per sec\n", thruput);
103 assert_eq!(result, num_bytes * size);
107 let args = os::args();
108 let args = if os::getenv("RUST_BENCH").is_some() {
109 vec!("".to_owned(), "1000000".to_owned(), "8".to_owned())
110 } else if args.len() <= 1u {
111 vec!("".to_owned(), "10000".to_owned(), "4".to_owned())
113 args.clone().move_iter().collect()
116 println!("{:?}", args);
117 run(args.as_slice());