Run
This commit is contained in:
parent
ea05e3ae49
commit
e76a92ee77
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -67,10 +67,21 @@ name = "lotto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"memory-stats",
|
||||||
"rand",
|
"rand",
|
||||||
"rayon",
|
"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]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
|
@ -132,3 +143,25 @@ name = "wasi"
|
||||||
version = "0.11.0+wasi-snapshot-preview1"
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
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"
|
||||||
|
|
|
@ -7,5 +7,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.82"
|
anyhow = "1.0.82"
|
||||||
|
memory-stats = "1.1.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rayon = "1.10.0"
|
rayon = "1.10.0"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# lotto
|
# lotto
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo run --release
|
RUSTFLAGS='-C opt-level=3 -C target-cpu=native' cargo run --release
|
||||||
```
|
```
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,9 +1,7 @@
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use std::fs::File;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::{
|
use std::{io::BufReader, time::Instant};
|
||||||
io::{stdin, BufReader},
|
|
||||||
time::Instant,
|
|
||||||
};
|
|
||||||
|
|
||||||
type Ticket = [u8; 5];
|
type Ticket = [u8; 5];
|
||||||
const NUM_ENTRIES: usize = 10_000_000;
|
const NUM_ENTRIES: usize = 10_000_000;
|
||||||
|
@ -57,9 +55,11 @@ fn num_matches(t1: Ticket, t2: Ticket) -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
|
let start = Instant::now();
|
||||||
println!("Parsing entries from stdin...");
|
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);
|
let mut entries = Vec::with_capacity(NUM_ENTRIES);
|
||||||
|
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
|
@ -71,7 +71,12 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
Err(_) => break,
|
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];
|
let winning = [68, 81, 40, 34, 85];
|
||||||
|
|
||||||
|
@ -89,8 +94,8 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Winners: {:?}\nTime Elapsed: {}ms",
|
"Winners: {:?}\nTime Elapsed: {}ms",
|
||||||
winners,
|
winners.into_iter().skip(2).collect::<Vec<usize>>(),
|
||||||
duration.subsec_millis()
|
duration.subsec_millis(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue