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) 1.969 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
ea01ee2 @brson Convert 'use' to 'extern mod'. Remove old 'use' syntax
brson authored
7 extern mod std;
f686896 @pcwalton test: "import" -> "use"
pcwalton authored
8 use io::Writer;
9 use io::WriterUtil;
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
10
11 enum request {
12 get_count,
13 bytes(uint),
14 stop
15 }
16
9c6890f @brson Convert more core types to camel case
brson authored
17 fn server(requests: comm::Port<request>, responses: comm::Chan<uint>) {
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
18 let mut count = 0u;
19 let mut done = false;
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
20 while !done {
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
21 match comm::recv(requests) {
025d866 @brson 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 @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
25 }
26 }
27 comm::send(responses, count);
28 }
29
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
30 fn run(args: ~[~str]) {
a76e433 @jruderman Add spawn_conversation
jruderman authored
31 let (from_child, to_child) = do task::spawn_conversation |po, ch| {
32 server(po, ch);
4220dcf @brson core: New task API
brson authored
33 };
4a78f9b @brson core: Demode option
brson authored
34 let size = uint::from_str(args[1]).get();
35 let workers = uint::from_str(args[2]).get();
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
36 let start = std::time::precise_time_s();
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Close…
msullivan authored
37 let mut worker_results = ~[];
d1fc2b5 @brson Convert to new closure syntax
brson authored
38 for uint::range(0u, workers) |_i| {
18ac4a8 @bblum Change task().future_result's argument mode
bblum authored
39 do task::task().future_result(|+r| {
67a8e71 @nikomatsakis Demode vec::push (and convert to method)
nikomatsakis authored
40 worker_results.push(r);
b30a58a @bblum Convert bench and run-pass tests to new task_builder interface
bblum authored
41 }).spawn {
d1fc2b5 @brson Convert to new closure syntax
brson authored
42 for uint::range(0u, size / workers) |_i| {
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
43 comm::send(to_child, bytes(100u));
44 }
4220dcf @brson core: New task API
brson authored
45 };
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
46 }
9cf271f @nikomatsakis De-mode vec::each() and many of the str iteration routines
nikomatsakis authored
47 for vec::each(worker_results) |r| {
48 future::get(r);
49 }
4220dcf @brson core: New task API
brson authored
50 comm::send(to_child, stop);
51 let result = comm::recv(from_child);
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
52 let end = std::time::precise_time_s();
53 let elapsed = end - start;
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
54 io::stdout().write_str(fmt!("Count is %?\n", result));
55 io::stdout().write_str(fmt!("Test took %? seconds\n", elapsed));
50fb4c3 @marijnh Increase precedence of as operator
marijnh authored
56 let thruput = ((size / workers * workers) as float) / (elapsed as float);
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
57 io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
58 }
59
edc317b @brson Remove arg vectors from main functions. Stop supporting them.
brson authored
60 fn main() {
61 let args = os::args();
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
62 let args = if os::getenv(~"RUST_BENCH").is_some() {
63 ~[~"", ~"1000000", ~"10000"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
64 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
65 ~[~"", ~"10000", ~"4"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
66 } else {
67 args
a76e433 @jruderman Add spawn_conversation
jruderman authored
68 };
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
69
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
70 debug!("%?", args);
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
71 run(args);
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
72 }
73
Something went wrong with that request. Please try again.