File: crcspeed.rs

package info (click to toggle)
rust-crc64 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: makefile: 4
file content (30 lines) | stat: -rw-r--r-- 768 bytes parent folder | download
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
use std::env;
use std::fs;
use std::time::Instant;

fn main() {
    let args = env::args().collect::<Vec<_>>();
    if args.len() == 1 {
        println!("Usage: {} [list of files]", args[0]);
        panic!();
    }

    let f = &args[1];
    let mut crc = 0;
    let content = fs::read(f).expect("can't read file");

    let sz = content.len();
    let size_mb = sz as f64 / 1024.0 / 1024.0;

    println!("CRC for {:.2} MB file", size_mb);

    let start = Instant::now();
    crc = crc64::crc64(crc, content.as_slice());
    let elapsed = start.elapsed();

    let total_time_seconds = elapsed.as_secs();
    let speed = size_mb / total_time_seconds as f64;

    println!("{:x}  {}", crc, f);
    println!("{} seconds at {:.2} MB/s", total_time_seconds, speed);
}