Last active
December 16, 2015 08:08
-
-
Save stepancheg/5403459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod extra; | |
use std::comm; | |
use std::io; | |
use extra::time; | |
fn to_us(ts: &time::Timespec) -> u64 { | |
ts.sec as u64 * 1000000 + ((ts.nsec / 1000) as u64) | |
} | |
fn now_us() -> u64 { | |
to_us(&time::get_time()) | |
} | |
// execute as RUST_THREADS=1 ./switch | |
// result is about 2us per switch | |
fn main() { | |
let (port1, chan1): (Port<int>, Chan<int>) = comm::stream(); | |
let (port2, chan2): (Port<int>, Chan<int>) = comm::stream(); | |
let steps = 100000; | |
do spawn || { | |
let mut i = 0; | |
while i < steps { | |
chan2.send(port1.recv()); | |
i += 1; | |
} | |
}; | |
let start = now_us(); | |
let mut i = 0; | |
while i < steps { | |
chan1.send(i as int); | |
port2.recv(); | |
i += 1; | |
} | |
let d = now_us() - start; | |
let per_step = d * 1000 / steps / 2; | |
io::println(per_step.to_str() + "ns"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment