From 7e4a7f3066368597d4f25d44dda3117c9ddec5db Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 13 Sep 2024 16:31:22 -0500 Subject: [PATCH] Stuff? --- Cargo.lock | 33 +++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 21 +++++++++++++-------- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70efa79..6d84d5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 677712a..8cb7dee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] anyhow = "1.0.82" +memory-stats = "1.1.0" rand = "0.8.5" rayon = "1.10.0" diff --git a/src/main.rs b/src/main.rs index 019f2bf..127badd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>(), + duration.subsec_millis(), ); Ok(())