Use busy loop in order to get accurate results
This commit is contained in:
parent
82697b7629
commit
e88942f680
@ -187,16 +187,21 @@ static CH_NTRU: &'static [u8] = b"\
|
|||||||
\x00\x2d\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03\
|
\x00\x2d\x00\x02\x01\x01\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03\
|
||||||
\x02\x03\x01";
|
\x02\x03\x01";
|
||||||
|
|
||||||
fn sleep(micros: u64, cmt: &'static str) {
|
fn sleep(micros: u128, cmt: &'static str) {
|
||||||
println!("[START] {}", cmt);
|
println!("[START] {}", cmt);
|
||||||
sleep_no_comment(micros);
|
sleep_no_comment(micros);
|
||||||
println!("[DONE] {}", cmt);
|
println!("[DONE] {}", cmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sleep_no_comment(micros: u64) {
|
fn sleep_no_comment(micros: u128) {
|
||||||
if micros > 0 {
|
if micros > 0 {
|
||||||
let dur_micros = time::Duration::from_micros(micros);
|
if micros > 1000 {
|
||||||
thread::sleep(dur_micros);
|
let dur_micros = time::Duration::from_micros(micros as u64);
|
||||||
|
thread::sleep(dur_micros);
|
||||||
|
} else {
|
||||||
|
let t1 = Instant::now();
|
||||||
|
while t1.elapsed().as_micros() < micros {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +263,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
let mut threads = Vec::new();
|
let mut threads = Vec::new();
|
||||||
// report every 1000 msgs sent
|
// report every 1000 msgs sent
|
||||||
let msg_nb_report = 1000;
|
let msg_nb_report = 1000;
|
||||||
|
// sleep time in microseconds between each message
|
||||||
|
let usleep = 1000000/msg_per_sec as u128;
|
||||||
for _ in 0..sending_threads {
|
for _ in 0..sending_threads {
|
||||||
// Condition variables to control threads
|
// Condition variables to control threads
|
||||||
let t = thread::spawn(move || {
|
let t = thread::spawn(move || {
|
||||||
@ -280,7 +287,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
_ => panic!("Unknown case"),
|
_ => panic!("Unknown case"),
|
||||||
};
|
};
|
||||||
s.shutdown(Shutdown::Both).expect("shutdown call failed");
|
s.shutdown(Shutdown::Both).expect("shutdown call failed");
|
||||||
sleep_no_comment(1000000/msg_per_sec as u64);
|
sleep_no_comment(usleep);
|
||||||
ch_sent += 1;
|
ch_sent += 1;
|
||||||
if ch_sent % msg_nb_report == 0 {
|
if ch_sent % msg_nb_report == 0 {
|
||||||
println!("nb of queries sent: total: {}. {1} msg's in {2} sec. {3} per sec",
|
println!("nb of queries sent: total: {}. {1} msg's in {2} sec. {3} per sec",
|
||||||
|
Loading…
Reference in New Issue
Block a user