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 Some(get_count) => { responses.send(count.clone()); }
39 //println!("server: received {:?} bytes", b);
42 None => { done = true; }
46 responses.send(count);
47 //println!("server exiting");
50 fn run(args: &[~str]) {
51 let (to_parent, from_child) = channel();
53 let size = from_str::<uint>(args[1]).unwrap();
54 let workers = from_str::<uint>(args[2]).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 let mut builder = task::task();
61 worker_results.push(builder.future_result());
62 builder.spawn(proc() {
63 for _ in range(0u, size / workers) {
64 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
65 to_child.send(bytes(num_bytes));
67 //println!("worker {:?} exiting", i);
71 let (to_child, from_parent) = channel();
72 for _ in range(0u, workers) {
73 let to_child = to_child.clone();
74 let mut builder = task::task();
75 worker_results.push(builder.future_result());
76 builder.spawn(proc() {
77 for _ in range(0u, size / workers) {
78 //println!("worker {:?}: sending {:?} bytes", i, num_bytes);
79 to_child.send(bytes(num_bytes));
81 //println!("worker {:?} exiting", i);
87 server(&from_parent, &to_parent);
90 for r in worker_results.iter() {
94 //println!("sending stop message");
95 //to_child.send(stop);
97 let result = from_child.recv();
98 let end = time::precise_time_s();
99 let elapsed = end - start;
100 print!("Count is {:?}\n", result);
101 print!("Test took {:?} seconds\n", elapsed);
102 let thruput = ((size / workers * workers) as f64) / (elapsed as f64);
103 print!("Throughput={} per sec\n", thruput);
104 assert_eq!(result, num_bytes * size);
108 let args = os::args();
109 let args = if os::getenv("RUST_BENCH").is_some() {
110 vec!(~"", ~"1000000", ~"8")
111 } else if args.len() <= 1u {
112 vec!(~"", ~"10000", ~"4")
114 args.clone().move_iter().collect()
117 println!("{:?}", args);
118 run(args.as_slice());