Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate time;
- use std::fs::{File};
- use std::io::Write;
- use std::thread;
- use std::time::Duration;
- const SYNCER: bool = true;
- fn worker(mut f: File) {
- let data = [0xffu8; 65536];
- for _ in 0..16384 {
- f.write_all(&data).unwrap();
- thread::sleep(Duration::new(0, 100_000));
- }
- }
- fn syncer(f: File) {
- loop {
- thread::sleep(Duration::from_millis(1));
- if SYNCER {
- f.sync_all().unwrap();
- }
- }
- }
- fn main() {
- println!("{}", if SYNCER { "sync" } else { "no sync" });
- let tm0 = time::precise_time_s();
- let f = File::create("output").unwrap();
- thread::spawn({
- let f = f.try_clone().unwrap();
- move || syncer(f)
- });
- let worker = thread::spawn({
- let f = f.try_clone().unwrap();
- move || worker(f)
- });
- worker.join().unwrap();
- let tm1 = time::precise_time_s();
- println!("writing: {}", tm1 - tm0);
- f.sync_all().unwrap();
- let tm2 = time::precise_time_s();
- println!("syncing: {}", tm2 - tm1);
- println!("total: {}", tm2 - tm0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement