diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index eec0105e5de7429babadd59ae496d33561481aa1..e2b407475b6e1520689575c2bd93c2ef14b82b44 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -3,9 +3,9 @@ use crate::{PortId, ProtocolDescription}; use crate::common::Id; use crate::protocol::eval::*; -const NUM_THREADS: u32 = 10; // number of threads in runtime -const NUM_INSTANCES: u32 = 10; // number of test instances constructed -const NUM_LOOPS: u32 = 10; // number of loops within a single test (not used by all tests) +const NUM_THREADS: u32 = 1; // number of threads in runtime +const NUM_INSTANCES: u32 = 4; // number of test instances constructed +const NUM_LOOPS: u32 = 4; // number of loops within a single test (not used by all tests) fn create_runtime(pdl: &str) -> Runtime { let protocol = ProtocolDescription::parse(pdl.as_bytes()).expect("parse pdl"); @@ -27,6 +27,27 @@ fn run_test_in_runtime(pdl: &str, constructor: // Wait until done :) } +struct TestTimer { + name: &'static str, + started: std::time::Instant +} + +impl TestTimer { + fn new(name: &'static str) -> Self { + Self{ name, started: std::time::Instant::now() } + } +} + +impl Drop for TestTimer { + fn drop(&mut self) { + let delta = std::time::Instant::now() - self.started; + let nanos = (delta.as_secs_f64() * 1_000_000.0) as u64; + let millis = nanos / 1000; + let nanos = nanos % 1000; + println!("[{}] Took {:>4}.{:03} ms", self.name, millis, nanos); + } +} + #[test] fn test_put_and_get() { const CODE: &'static str = " @@ -34,7 +55,6 @@ fn test_put_and_get() { u32 index = 0; while (index < loops) { synchronous { - print(\"putting!\"); put(sender, true); } index += 1; @@ -45,7 +65,6 @@ fn test_put_and_get() { u32 index = 0; while (index < loops) { synchronous { - print(\"getting!\"); auto result = get(receiver); assert(result); } @@ -54,6 +73,7 @@ fn test_put_and_get() { } "; + let thing = TestTimer::new("hello"); run_test_in_runtime(CODE, |api| { let channel = api.create_channel();