From bd5e0e01e69b34e054350f6fbb2790bac4b8efa7 Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:14:19 -0600 Subject: [PATCH 1/6] Upgrades crates --- Cargo.lock | 316 +++++++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 8 +- 2 files changed, 277 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 649aa00..aa007f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,111 +1,341 @@ -[root] -name = "wargame-rust" -version = "0.3.0" +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ - "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] -name = "advapi32-sys" +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "libc", ] [[package]] -name = "aho-corasick" -version = "0.4.0" +name = "getrandom" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ - "memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "wasi", ] [[package]] -name = "env_logger" -version = "0.3.2" +name = "hermit-abi" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ - "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.46 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] -name = "kernel32-sys" -version = "0.2.1" +name = "humantime" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] name = "libc" -version = "0.2.4" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" -version = "0.3.4" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] [[package]] name = "memchr" -version = "0.1.7" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "rand_chacha", + "rand_core", ] [[package]] -name = "rand" -version = "0.3.12" +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", ] [[package]] name = "regex" -version = "0.1.46" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ - "aho-corasick 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.2.2" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] [[package]] name = "time" -version = "0.1.34" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ - "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", + "time-core", ] +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "wargame-rust" +version = "0.3.0" +dependencies = [ + "env_logger", + "log", + "rand", + "time", +] + +[[package]] +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.2.5" +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-build" -version = "0.1.1" +name = "winapi-util" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml index fe325cf..15f47b6 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "0.3.0" authors = ["Ryan Rampersad "] [dependencies] -rand = "0.3" -log = "0.3" -env_logger = "*" -time = "0.1" +rand = "0.8.5" +log = "0.4.17" +env_logger = "0.10.0" +time = "0.3.17" From 6d63076dc06603b2a028f510adef96af33a35f32 Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:18:15 -0600 Subject: [PATCH 2/6] Removes env_logger unwrap --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5f7676a..9ffc1a5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ pub mod benchmark; use std::env; fn main() { - env_logger::init().unwrap(); + env_logger::init(); /* Grab the optional cli argument. From 8738fc3f0f9f20759fc50ce604b160679509d6c5 Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:19:24 -0600 Subject: [PATCH 3/6] Update rand imports --- src/wg.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wg.rs b/src/wg.rs index fbdc0bc..0e7f28a 100755 --- a/src/wg.rs +++ b/src/wg.rs @@ -1,6 +1,5 @@ use std::fmt; -use rand::Rng; -use rand::ThreadRng; +use rand::{rngs::ThreadRng, seq::SliceRandom}; use std::cmp::Ordering; /// Value represents the Value the card. From 6b8e1d9ebef65bd29d92caee12008ce917dc7842 Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:20:13 -0600 Subject: [PATCH 4/6] Swaps out shuffle implementation --- src/wg.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wg.rs b/src/wg.rs index 0e7f28a..433f83c 100755 --- a/src/wg.rs +++ b/src/wg.rs @@ -1,5 +1,5 @@ use std::fmt; -use rand::{rngs::ThreadRng, seq::SliceRandom}; +use rand::{rngs::ThreadRng, seq::SliceRandom}; use std::cmp::Ordering; /// Value represents the Value the card. @@ -229,8 +229,7 @@ impl Deck { // previously, this used a fresh ThreadRng // each call, but instead relies on a generator // being passed - rng.shuffle(cards); - + cards.shuffle(rng); } /// Get the length of the deck of cards. From ccbc52e1d58b46adb2b59124e27b6ac386304fdf Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:20:37 -0600 Subject: [PATCH 5/6] Adds allow unused_labels for 'war tag --- src/wg.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wg.rs b/src/wg.rs index 433f83c..b11282a 100755 --- a/src/wg.rs +++ b/src/wg.rs @@ -229,7 +229,7 @@ impl Deck { // previously, this used a fresh ThreadRng // each call, but instead relies on a generator // being passed - cards.shuffle(rng); + cards.shuffle(rng); } /// Get the length of the deck of cards. @@ -294,6 +294,7 @@ impl fmt::Display for Deck { } } +#[allow(unused_labels)] /// Play the game of War. pub fn game(rng: &mut ThreadRng) { From 5dc8c785d8650e950f1cb037eb3d398e50b9e465 Mon Sep 17 00:00:00 2001 From: Ryan Rampersad Date: Thu, 29 Dec 2022 22:21:07 -0600 Subject: [PATCH 6/6] Refactor precise_time_ns with Instant, switch to u128 for nanos --- src/benchmark.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/benchmark.rs b/src/benchmark.rs index ee1c41f..380143d 100755 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -1,5 +1,3 @@ -use time::precise_time_ns; - use std::sync::mpsc::channel; use std::sync::mpsc::Sender; use std::sync::mpsc::Receiver; @@ -12,10 +10,13 @@ use std::collections::HashMap; use rand; +use std::time::Instant; + use wg; -const MS:u64 = 1000000; -const NS:u64 = 1000000000; + +const MS:u128 = 1_000_000; +const NS:u128 = 1_000_000_000; pub fn benchmark(threads: usize, multiplier: f64) { @@ -28,34 +29,34 @@ pub fn benchmark(threads: usize, multiplier: f64) { create_threads(threads, &mut terminate_senders, &mut termination_receivers, &mut completion_receivers); // 1/10 of a second - const DISPLAY_FREQUENCY:u64 = NS/10; + const DISPLAY_FREQUENCY:u128 = NS/10; // 1/200 of a second - const SAMPLE_FREQUENCY:u64 = NS/200; + const SAMPLE_FREQUENCY:u128 = NS/200; // 10 seconds - let mut prime_time:u64 = 10000000000; + let mut prime_time:u128 = 10000000000; // 50 seconds - let mut sample_time:u64 = 50000000000; + let mut sample_time:u128 = 50000000000; if multiplier != 1.00 { - prime_time = (prime_time as f64 * multiplier) as u64; - sample_time = (sample_time as f64 * multiplier) as u64; + prime_time = (prime_time as f64 * multiplier) as u128; + sample_time = (sample_time as f64 * multiplier) as u128; } - let end_time:u64 = prime_time + sample_time; + let end_time:u128 = prime_time + sample_time; - let sample_size:u64 = sample_time / SAMPLE_FREQUENCY; + let sample_size:u128 = sample_time / SAMPLE_FREQUENCY; // samples used for statistics calculations let mut samples = Vec::with_capacity(sample_size as usize); - let start_time:u64 = precise_time_ns(); - let mut current_time:u64; - let mut elapsed_time:u64; + let start_time:Instant = Instant::now(); + let mut current_time:Instant; + let mut elapsed_time:u128; - let mut last_display_time:u64 = start_time; - let mut last_sample_time:u64 = start_time; + let mut last_display_time:Instant = start_time; + let mut last_sample_time:Instant = start_time; let mut phase:u64 = 1; @@ -74,8 +75,8 @@ pub fn benchmark(threads: usize, multiplier: f64) { total_games = total_games + get_games(&completion_receivers); // time calculations - current_time = precise_time_ns(); - elapsed_time = current_time - start_time; + current_time = Instant::now(); + elapsed_time = current_time.duration_since(start_time).as_nanos(); speed = total_games as f64 / elapsed_time as f64; @@ -101,12 +102,12 @@ pub fn benchmark(threads: usize, multiplier: f64) { break 'monitor; } - if phase == 2 && (current_time - last_sample_time) > SAMPLE_FREQUENCY { + if phase == 2 && (current_time.duration_since(last_sample_time).as_nanos()) > SAMPLE_FREQUENCY { last_sample_time = current_time; samples.push(speed); } - if (current_time - last_display_time) > DISPLAY_FREQUENCY { + if (current_time.duration_since(last_display_time).as_nanos()) > DISPLAY_FREQUENCY { last_display_time = current_time; if phase == 1 {