Last active
June 21, 2022 06:31
-
-
Save tropicbliss/57c9f29d169f25bd5ecb7dfeff677282 to your computer and use it in GitHub Desktop.
Extremely fast loop unrolled fizz buzz
This file contains hidden or 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::io::{self, Write}; | |
fn main() { | |
const BUFFER_CAPACITY: usize = 64 * 1024; | |
let stdout = io::stdout(); | |
let handle = stdout.lock(); | |
let mut handle = io::BufWriter::with_capacity(BUFFER_CAPACITY, handle); | |
let mut i: usize = 0; | |
loop { | |
i += 1; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\n").unwrap(); | |
i += 1; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\nFizz\n").unwrap(); | |
i += 2; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\nBuzz\nFizz\n").unwrap(); | |
i += 3; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\n").unwrap(); | |
i += 1; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\nFizz\nBuzz\n").unwrap(); | |
i += 3; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\nFizz\n").unwrap(); | |
i += 2; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\n").unwrap(); | |
i += 1; | |
itoap::write(&mut handle, i).unwrap(); | |
handle.write(b"\nFizzBuzz\n").unwrap(); | |
i += 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment