performance measurements

Each table row shows performance measurements for this Rust program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,0002.962.97385,936440  0% 1% 2% 100%
5,000,00027.1027.1364,400440  0% 8% 1% 100%
50,000,000269.75269.9450,060440  0% 1% 1% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.

 notes

rustc 1.0.0-alpha (44a287e6e 2015-01-08 17:03:40 -0800)

 thread-ring Rust program source code

// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// contributed by the Rust Project Developers
// contributed by TeXitoi

use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread::Thread;

fn start(n_tasks: i32, token: i32) {
    let (tx, mut rx) = channel();
    tx.send(token).unwrap();
    let mut guards = Vec::with_capacity(n_tasks as usize);
    for i in 2 .. n_tasks + 1 {
        let (tx, next_rx) = channel();
        let cur_rx = std::mem::replace(&mut rx, next_rx);
        guards.push(Thread::scoped(move|| roundtrip(i, tx, cur_rx)));
    }
    let guard = Thread::scoped(move|| roundtrip(1, tx, rx));
}

fn roundtrip(id: i32, tx: Sender<i32>, rx: Receiver<i32>) {
    for token in rx.iter() {
        if token == 1 {
            println!("{}", id);
            break;
        }
        tx.send(token - 1).unwrap();
    }
}

fn main() {
    let args = std::os::args();
    let token = args.get(1).and_then(|arg| arg.parse()).unwrap_or(1000);
    let n_tasks = args.get(2).and_then(|arg| arg.parse()).unwrap_or(503);
    start(n_tasks, token);
}

 make, command-line, and program output logs

Sat, 10 Jan 2015 22:36:17 GMT

MAKE:
/usr/local/src/rust/bin/rustc -C opt-level=3 -C target-cpu=core2 -C lto threadring.rs -o threadring.rust_run
threadring.rs:19:9: 19:14 warning: unused variable: `guard`, #[warn(unused_variables)] on by default
threadring.rs:19     let guard = Thread::scoped(move|| roundtrip(1, tx, rx));
                         ^~~~~
threadring.rs:17:21: 17:35 warning: use of unstable item: may change with specifics of new Send semantics
threadring.rs:17         guards.push(Thread::scoped(move|| roundtrip(i, tx, cur_rx)));
                                     ^~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
threadring.rs:19:17: 19:31 warning: use of unstable item: may change with specifics of new Send semantics
threadring.rs:19     let guard = Thread::scoped(move|| roundtrip(1, tx, rx));
                                 ^~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
threadring.rs:33:16: 33:29 warning: use of unstable item
threadring.rs:33     let args = std::os::args();
                                ^~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
threadring.rs:34:48: 34:55 warning: use of unstable item: this method was just created
threadring.rs:34     let token = args.get(1).and_then(|arg| arg.parse()).unwrap_or(1000);
                                                                ^~~~~~~
note: this feature may not be used in the beta release channel
threadring.rs:35:50: 35:57 warning: use of unstable item: this method was just created
threadring.rs:35     let n_tasks = args.get(2).and_then(|arg| arg.parse()).unwrap_or(503);
                                                                  ^~~~~~~
note: this feature may not be used in the beta release channel
rm threadring.rs
9.47s to complete and log all make actions

COMMAND LINE:
./threadring.rust_run 50000000

PROGRAM OUTPUT:
292

Revised BSD license

  Home   Conclusions   License   Play