Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (66 sloc) 2.076 kb
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis 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 use std;
6f5853f @graydon Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
8 import io::writer;
9 import io::writer_util;
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
10
11 enum request {
12 get_count,
13 bytes(uint),
14 stop
15 }
16
17 fn server(requests: comm::port<request>, responses: comm::chan<uint>) {
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
18 let mut count = 0u;
19 let mut done = false;
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
20 while !done {
21 alt comm::recv(requests) {
22 get_count { comm::send(responses, copy count); }
23 bytes(b) { count += b; }
24 stop { done = true; }
25 }
26 }
27 comm::send(responses, count);
28 }
29
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
30 fn run(args: ~[str]) {
4220dcf @brson core: New task API
brson authored
31 let from_child = comm::port();
32 let to_parent = comm::chan(from_child);
d1fc2b5 @brson Convert to new closure syntax
brson authored
33 let to_child = do task::spawn_listener |po| {
4220dcf @brson core: New task API
brson authored
34 server(po, to_parent);
35 };
ffd50b9 @marijnh Make the various from_str functions return options
marijnh authored
36 let size = option::get(uint::from_str(args[1]));
37 let workers = option::get(uint::from_str(args[2]));
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
38 let start = std::time::precise_time_s();
4220dcf @brson core: New task API
brson authored
39 let to_child = to_child;
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
40 let mut worker_results = ~[];
d1fc2b5 @brson Convert to new closure syntax
brson authored
41 for uint::range(0u, workers) |_i| {
98b07dd @catamorphism Rename task::task_builder to task::builder
catamorphism authored
42 let builder = task::builder();
3ba7ca5 @eholk Improved perf for msgsend (Issue #2719)
eholk authored
43 vec::push(worker_results, task::future_result(builder));
d1fc2b5 @brson Convert to new closure syntax
brson authored
44 do task::run(builder) || {
45 for uint::range(0u, size / workers) |_i| {
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
46 comm::send(to_child, bytes(100u));
47 }
4220dcf @brson core: New task API
brson authored
48 };
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
49 }
d1fc2b5 @brson Convert to new closure syntax
brson authored
50 vec::iter(worker_results, |r| { future::get(r); } );
4220dcf @brson core: New task API
brson authored
51 comm::send(to_child, stop);
52 let result = comm::recv(from_child);
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
53 let end = std::time::precise_time_s();
54 let elapsed = end - start;
6f5853f @graydon Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
55 io::stdout().write_str(#fmt("Count is %?\n", result));
56 io::stdout().write_str(#fmt("Test took %? seconds\n", elapsed));
50fb4c3 @marijnh Increase precedence of as operator
marijnh authored
57 let thruput = ((size / workers * workers) as float) / (elapsed as float);
6f5853f @graydon Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
58 io::stdout().write_str(#fmt("Throughput=%f per sec\n", thruput));
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
59 }
60
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
61 fn main(args: ~[str]) {
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
62 let args = if os::getenv("RUST_BENCH").is_some() {
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
63 ~["", "1000000", "10000"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
64 } else if args.len() <= 1u {
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
65 ~["", "10000", "4"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
66 } else {
67 args
68 };
69
70 #debug("%?", args);
71 run(args);
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
72 }
73
Something went wrong with that request. Please try again.