diff --git a/Cargo.toml b/Cargo.toml index 6793da4..37658f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,6 @@ edition = "2024" [dependencies] rand = { version = "0.9.0", features = ["small_rng", "std_rng"] } + +[profile.release] +lto = "fat" diff --git a/src/main.rs b/src/main.rs index c75a397..cc8976a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,24 @@ -use std::io::{self, BufWriter, Write}; +use std::io::{self, Write}; -use rand::{distr::StandardUniform, rngs::SmallRng, Rng, SeedableRng}; +use rand::{Rng, SeedableRng, rngs::SmallRng}; + +const BUFFER_SIZE: usize = 8192; +const BITS_PER_SAMPLE: usize = u64::BITS as usize; fn main() { - let mut stdout = BufWriter::new(io::stdout().lock()); - let rng = SmallRng::from_os_rng(); + let mut stdout = io::stdout().lock(); + let mut rng = SmallRng::from_os_rng(); - for bits in rng.sample_iter::<u64, _>(StandardUniform) { - for i in 0..64 { - let bit = (bits >> i) & 1; - let c = if bit == 0 { b'/' } else { b'\\' }; - let _ = stdout.write_all(&[c]); + let mut buf_out = [b'A'; BUFFER_SIZE]; + loop { + for chunk_idx in 0..(BUFFER_SIZE / BITS_PER_SAMPLE) { + let bits: u64 = rng.random(); + for bit_idx in 0..BITS_PER_SAMPLE { + let bit = (bits >> bit_idx) & 1; + let c = if bit == 0 { b'\\' } else { b'/' }; + buf_out[chunk_idx * BITS_PER_SAMPLE + bit_idx] = c; + } } + let _ = stdout.write_all(&buf_out); } }