In Rust, sometimes the biggest performance overhead is repeated locking of 
stdout. To avoid it, one would lock the stdout before the loop. I wonder Nim 
requires locking as well.
    
    
    {
        let mut out = File::new("test.out");
        let mut buf = BufWriter::new(out);
        let mut lock = io::stdout().lock();
        writeln!(lock, "{}", header);
        for line in lines {
            writeln!(lock, "{}", line);
            writeln!(buf, "{}", line);
        }
        writeln!(lock, "{}", footer);
    }   // end scope to unlock stdout and flush/close buf
    
    
    Run

Reply via email to