Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 61 lines (54 sloc) 1.743 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;
8 import std::io::writer;
9 import std::io::writer_util;
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>) {
18 let count = 0u;
19 let done = false;
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
30 fn run(args: [str]) {
31 let server = task::spawn_connected(server);
32 let size = uint::from_str(args[1]);
33 let workers = uint::from_str(args[2]);
34 let start = std::time::precise_time_s();
35 let to_child = server.to_child;
36 let worker_tasks = [];
37 uint::range(0u, workers) {|_i|
38 worker_tasks += [task::spawn_joinable {||
39 uint::range(0u, size / workers) {|_i|
40 comm::send(to_child, bytes(100u));
41 }
42 }];
43 }
44 vec::iter(worker_tasks) {|t| task::join(t); }
45 comm::send(server.to_child, stop);
46 let result = comm::recv(server.from_child);
47 let end = std::time::precise_time_s();
48 let elapsed = end - start;
49 std::io::stdout().write_str(#fmt("Count is %?\n", result));
50 std::io::stdout().write_str(#fmt("Test took %? seconds\n", elapsed));
50fb4c3 @marijnh Increase precedence of as operator
marijnh authored
51 let thruput = ((size / workers * workers) as float) / (elapsed as float);
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
52 std::io::stdout().write_str(#fmt("Throughput=%f per sec\n", thruput));
53 }
54
55 fn main(args: [str]) {
56 let args1 = if vec::len(args) <= 1u { ["", "10000", "4"] } else { args };
57 #debug("%?", args1);
58 run(args1);
59 }
60
Something went wrong with that request. Please try again.