This commit is contained in:
Daniel Flanagan 2024-09-13 16:31:22 -05:00
parent ea05e3ae49
commit 7e4a7f3066
3 changed files with 47 additions and 8 deletions

33
Cargo.lock generated
View file

@ -67,10 +67,21 @@ name = "lotto"
version = "0.1.0"
dependencies = [
"anyhow",
"memory-stats",
"rand",
"rayon",
]
[[package]]
name = "memory-stats"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34f79cf9964c5c9545493acda1263f1912f8d2c56c8a2ffee2606cb960acaacc"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@ -132,3 +143,25 @@ name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -7,5 +7,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0.82"
memory-stats = "1.1.0"
rand = "0.8.5"
rayon = "1.10.0"

View file

@ -1,9 +1,7 @@
use anyhow::anyhow;
use std::fs::File;
use std::io::BufRead;
use std::{
io::{stdin, BufReader},
time::Instant,
};
use std::{io::BufReader, time::Instant};
type Ticket = [u8; 5];
const NUM_ENTRIES: usize = 10_000_000;
@ -57,9 +55,11 @@ fn num_matches(t1: Ticket, t2: Ticket) -> usize {
}
fn main() -> Result<(), anyhow::Error> {
let start = Instant::now();
println!("Parsing entries from stdin...");
let reader = BufReader::new(stdin());
let f = File::open("/mytmpfs/10m-v2.txt")?;
let reader = BufReader::new(f);
let mut entries = Vec::with_capacity(NUM_ENTRIES);
for line in reader.lines() {
@ -71,7 +71,12 @@ fn main() -> Result<(), anyhow::Error> {
Err(_) => break,
}
}
println!("{} entries parsed from stdin", entries.len());
let duration = start.elapsed();
println!(
"{} entries parsed from stdin in {}ms",
entries.len(),
duration.as_millis()
);
let winning = [68, 81, 40, 34, 85];
@ -89,8 +94,8 @@ fn main() -> Result<(), anyhow::Error> {
println!(
"Winners: {:?}\nTime Elapsed: {}ms",
winners,
duration.subsec_millis()
winners.into_iter().skip(2).collect::<Vec<usize>>(),
duration.subsec_millis(),
);
Ok(())