Created
October 1, 2022 15:58
-
-
Save umurgdk/ce3ecaf4cc434a5655df29aa6e356fc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
fs, | |
io::{self, BufWriter, Write}, | |
time::Instant, | |
}; | |
fn main() -> io::Result<()> { | |
println!("Hello, world!"); | |
let file = fs::File::create("output.txt")?; | |
let mut logID = 0; | |
let mut total_written_bytes = 0; | |
let msg = "This is a long line of log text with the id is"; | |
let mut writer = BufWriter::with_capacity(10_024_000, file); | |
let begin = Instant::now(); | |
loop { | |
let written_bytes = writer.write(msg.as_bytes())?; | |
total_written_bytes += written_bytes; | |
logID += 1; | |
if total_written_bytes >= 512_000_000 { | |
break; | |
} | |
} | |
writer.flush()?; | |
let total_duration = Instant::now().duration_since(begin); | |
let total_seconds = total_duration.as_secs_f64(); | |
let total_megabytes = (total_written_bytes as f64) / 1_024_000.0; | |
let megabytes_per_second = total_megabytes / total_seconds; | |
println!( | |
"Wrote {} mbytes in {} seconds, {} mb/s", | |
total_megabytes as i64, total_seconds, megabytes_per_second | |
); | |
return Ok(()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment