Skip to content

Instantly share code, notes, and snippets.

@wayslog
Created June 6, 2017 11:54
Show Gist options
  • Save wayslog/15d6ec1d7ef8ea940f2ef4b7ff1251d5 to your computer and use it in GitHub Desktop.
Save wayslog/15d6ec1d7ef8ea940f2ef4b7ff1251d5 to your computer and use it in GitHub Desktop.
use std::time::SystemTime;
fn main() {
let letters: String = (b'a'..b'z' + 1).map(|c| c as char).collect();
let repeated = letters.repeat(1000_0000);
let now = SystemTime::now();
let mut rslt: Vec<_> = (0..26).map(|_| 0).collect();
for ch in repeated.chars() {
let pos = ch as usize - 'a' as usize;
rslt[pos] += 1;
}
for (idx, val) in rslt.iter().enumerate() {
print!("{}: {}", ((idx + 'a' as usize) as u8) as char, val);
}
let elapsed = now.elapsed().unwrap();
println!("\ntime: {}.{:09}s ",
elapsed.as_secs(),
elapsed.subsec_nanos());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment