Explorar el Código

Use busy loop in order to get accurate results

master
Henry Case hace 5 años
padre
commit
e88942f680
Se han modificado 1 ficheros con 12 adiciones y 5 borrados
  1. +12
    -5
      rawhammer/src/main.rs

+ 12
- 5
rawhammer/src/main.rs Ver fichero

@@ -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);
thread::sleep(dur_micros);
if micros > 1000 {
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",


Cargando…
Cancelar
Guardar