Skip to content

Instantly share code, notes, and snippets.

@tropicbliss
Last active June 21, 2022 06:31
Show Gist options
  • Save tropicbliss/57c9f29d169f25bd5ecb7dfeff677282 to your computer and use it in GitHub Desktop.
Save tropicbliss/57c9f29d169f25bd5ecb7dfeff677282 to your computer and use it in GitHub Desktop.
Extremely fast loop unrolled fizz buzz
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