Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (63 sloc) 1.963 kb
5660b8b Niko Matsakis 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
ea01ee2 Brian Anderson Convert 'use' to 'extern mod'. Remove old 'use' syntax
brson authored
7 extern mod std;
f686896 Patrick Walton test: "import" -> "use"
pcwalton authored
8 use io::Writer;
9 use io::WriterUtil;
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
10
11 enum request {
12 get_count,
13 bytes(uint),
14 stop
15 }
16
9c6890f Brian Anderson Convert more core types to camel case
brson authored
17 fn server(requests: comm::Port<request>, responses: comm::Chan<uint>) {
dc07280 Niko Matsakis 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 Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
20 while !done {
ecaf9e3 Brian Anderson Convert alt to match. Stop parsing alt
brson authored
21 match comm::recv(requests) {
025d866 Brian Anderson Switch alts to use arrows
brson authored
22 get_count => { comm::send(responses, copy count); }
23 bytes(b) => { count += b; }
24 stop => { done = true; }
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
25 }
26 }
27 comm::send(responses, count);
28 }
29
92743dc Michael J. Sullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
30 fn run(args: ~[~str]) {
a76e433 Jesse Ruderman Add spawn_conversation
jruderman authored
31 let (from_child, to_child) = do task::spawn_conversation |po, ch| {
32 server(po, ch);
4220dcf Brian Anderson core: New task API
brson authored
33 };
ffd50b9 Marijn Haverbeke Make the various from_str functions return options
marijnh authored
34 let size = option::get(uint::from_str(args[1]));
35 let workers = option::get(uint::from_str(args[2]));
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
36 let start = std::time::precise_time_s();
98e161f Michael J. Sullivan Switch the compiler over to using ~[] notation instead of []/~. Closes #...
msullivan authored
37 let mut worker_results = ~[];
d1fc2b5 Brian Anderson Convert to new closure syntax
brson authored
38 for uint::range(0u, workers) |_i| {
18ac4a8 Ben Blum Change task().future_result's argument mode
bblum authored
39 do task::task().future_result(|+r| {
b30a58a Ben Blum Convert bench and run-pass tests to new task_builder interface
bblum authored
40 vec::push(worker_results, r);
41 }).spawn {
d1fc2b5 Brian Anderson Convert to new closure syntax
brson authored
42 for uint::range(0u, size / workers) |_i| {
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
43 comm::send(to_child, bytes(100u));
44 }
4220dcf Brian Anderson core: New task API
brson authored
45 };
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
46 }
9600744 Graydon Hoare fix more fallout from future de-mode-ing.
graydon authored
47 vec::iter(worker_results, |r| { future::get(&r); } );
4220dcf Brian Anderson core: New task API
brson authored
48 comm::send(to_child, stop);
49 let result = comm::recv(from_child);
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
50 let end = std::time::precise_time_s();
51 let elapsed = end - start;
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
52 io::stdout().write_str(fmt!("Count is %?\n", result));
53 io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed));
50fb4c3 Marijn Haverbeke Increase precedence of as operator
marijnh authored
54 let thruput = ((size / workers * workers) as float) / (elapsed as float);
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
55 io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
56 }
57
92743dc Michael J. Sullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
58 fn main(args: ~[~str]) {
59 let args = if os::getenv(~"RUST_BENCH").is_some() {
60 ~[~"", ~"1000000", ~"10000"]
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
61 } else if args.len() <= 1u {
92743dc Michael J. Sullivan Move the world over to using the new style string literals and types. Cl...
msullivan authored
62 ~[~"", ~"10000", ~"4"]
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
63 } else {
64 args
a76e433 Jesse Ruderman Add spawn_conversation
jruderman authored
65 };
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
66
29f32b4 Paul Stansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
67 debug!("%?", args);
4fec4cd Brian Anderson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
68 run(args);
5660b8b Niko Matsakis add msgsend.rs to benchmarks
nikomatsakis authored
69 }
70
Something went wrong with that request. Please try again.