Add timing
This commit is contained in:
parent
d93d0b49a5
commit
82697b7629
@ -1,6 +1,6 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net::*;
|
use std::net::*;
|
||||||
use std::time::Duration;
|
use std::time::{Duration, Instant};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time;
|
use std::time;
|
||||||
use clap::{Arg, App};
|
use clap::{Arg, App};
|
||||||
@ -194,7 +194,6 @@ fn sleep(micros: u64, cmt: &'static str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sleep_no_comment(micros: u64) {
|
fn sleep_no_comment(micros: u64) {
|
||||||
println!("micros {}", micros);
|
|
||||||
if micros > 0 {
|
if micros > 0 {
|
||||||
let dur_micros = time::Duration::from_micros(micros);
|
let dur_micros = time::Duration::from_micros(micros);
|
||||||
thread::sleep(dur_micros);
|
thread::sleep(dur_micros);
|
||||||
@ -257,12 +256,14 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
// Start a thread which sends CH
|
// Start a thread which sends CH
|
||||||
let mut threads = Vec::new();
|
let mut threads = Vec::new();
|
||||||
|
// report every 1000 msgs sent
|
||||||
|
let msg_nb_report = 1000;
|
||||||
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 || {
|
||||||
// calculates number of sent client hellos
|
// calculates number of sent client hellos
|
||||||
let mut ch_sent = 0;
|
let mut ch_sent = 0;
|
||||||
|
let mut now = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
// try connect
|
// try connect
|
||||||
let sock = TcpStream::connect_timeout(&sock_addr, dur);
|
let sock = TcpStream::connect_timeout(&sock_addr, dur);
|
||||||
@ -281,8 +282,13 @@ fn main() -> std::io::Result<()> {
|
|||||||
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(1000000/msg_per_sec as u64);
|
||||||
ch_sent += 1;
|
ch_sent += 1;
|
||||||
if ch_sent % 100 == 0 {
|
if ch_sent % msg_nb_report == 0 {
|
||||||
println!("nb of queries sent: {}", ch_sent);
|
println!("nb of queries sent: total: {}. {1} msg's in {2} sec. {3} per sec",
|
||||||
|
ch_sent,
|
||||||
|
msg_nb_report,
|
||||||
|
now.elapsed().as_millis() as f64/1000 as f64,
|
||||||
|
((msg_nb_report as f64 / now.elapsed().as_millis() as f64) * 1000 as f64) as i64);
|
||||||
|
now = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user