-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperf_debug.rs
44 lines (38 loc) · 1.28 KB
/
perf_debug.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// prints the received stream as 2 16 bit values.
// useful for debugging performance
use byteorder::{LittleEndian, ReadBytesExt};
use ft60x::ft60x::{FT60x, DEFAULT_PID, DEFAULT_VID};
use std::io::Cursor;
use std::time::SystemTime;
type Result<T> = std::result::Result<T, ft60x::Error>;
fn main() -> Result<()> {
let ft60x = FT60x::new(DEFAULT_VID, DEFAULT_PID)?;
let mut consumer = ft60x.data_stream_ringbuf(1024 * 1024 * 128)?;
let mut start = SystemTime::now();
let mut last_i = 0;
while consumer
.with_next_buffer(|buf| {
let mut cursor = Cursor::new(&buf[..]);
while let (Ok(i), Ok(j)) = (
cursor.read_u16::<LittleEndian>(),
cursor.read_u16::<LittleEndian>(),
) {
if j > 0 {
eprintln!("{}, {}", last_i, j);
}
last_i = i;
}
let bytes = buf.len() as f64;
let elapsed = start.elapsed().unwrap().as_secs_f64();
start = SystemTime::now();
eprintln!(
"elapsed (for {} Mb) {}s = {} MB/s",
bytes / 1024. / 1024.,
elapsed,
bytes / 1024. / 1024. / elapsed
);
})
.is_ok()
{}
Ok(())
}