Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 67 lines (60 sloc) 1.937 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
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);
33 let to_child = task::spawn_listener {|po|
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;
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining file...
nikomatsakis authored
40 let mut worker_results = [];
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
41 uint::range(0u, workers) {|_i|
cd72b1f @brson Overhaul constructor naming in libs
brson authored
42 let builder = task::task_builder();
4220dcf @brson core: New task API
brson authored
43 worker_results += [task::future_result(builder)];
44 task::run(builder) {||
5660b8b @nikomatsakis add msgsend.rs to benchmarks
nikomatsakis authored
45 uint::range(0u, size / workers) {|_i|
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 }
4220dcf @brson core: New task API
brson authored
50 vec::iter(worker_results) {|r| future::get(r); }
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
61 fn main(args: [str]) {
62 let args1 = if vec::len(args) <= 1u { ["", "10000", "4"] } else { args };
63 #debug("%?", args1);
64 run(args1);
65 }
66
Something went wrong with that request. Please try again.