make it about three times faster

This commit is contained in:
mehbark 2025-03-20 15:28:01 -04:00
parent bd42388e69
commit c88b45dd13
2 changed files with 20 additions and 9 deletions

View file

@ -5,3 +5,6 @@ edition = "2024"
[dependencies] [dependencies]
rand = { version = "0.9.0", features = ["small_rng", "std_rng"] } rand = { version = "0.9.0", features = ["small_rng", "std_rng"] }
[profile.release]
lto = "fat"

View file

@ -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() { fn main() {
let mut stdout = BufWriter::new(io::stdout().lock()); let mut stdout = io::stdout().lock();
let rng = SmallRng::from_os_rng(); let mut rng = SmallRng::from_os_rng();
for bits in rng.sample_iter::<u64, _>(StandardUniform) { let mut buf_out = [b'A'; BUFFER_SIZE];
for i in 0..64 { loop {
let bit = (bits >> i) & 1; for chunk_idx in 0..(BUFFER_SIZE / BITS_PER_SAMPLE) {
let c = if bit == 0 { b'/' } else { b'\\' }; let bits: u64 = rng.random();
let _ = stdout.write_all(&[c]); 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);
}
} }