feat: add num_cpus

This commit is contained in:
2020-09-20 23:11:30 +08:00
parent ccc820145e
commit 81a0145be4
3 changed files with 31 additions and 8 deletions

20
btc-address/Cargo.lock generated
View File

@@ -46,6 +46,7 @@ dependencies = [
"bs58",
"digest",
"hex",
"num_cpus",
"rand",
"ripemd160",
"secp256k1",
@@ -109,6 +110,15 @@ dependencies = [
"typenum",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.2"
@@ -121,6 +131,16 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "opaque-debug"
version = "0.2.3"

View File

@@ -16,4 +16,5 @@ rand = "0.6"
digest = "0.8.1"
ripemd160 = "0.8.0"
sha2 = "0.8.1"
num_cpus = "1.13.0"

View File

@@ -1,21 +1,23 @@
use std::{
thread,
sync::{ Arc, Mutex, },
};
use std::{ thread, sync::{ Arc, Mutex } };
use rand::rngs::OsRng;
use secp256k1::{ Secp256k1, key::PublicKey, };
use secp256k1::{ Secp256k1, key::PublicKey };
use sha2::Sha256;
use ripemd160::Ripemd160;
use digest::{ Input, FixedOutput, };
use digest::{ Input, FixedOutput };
const PREFIX: &[&str] = &["1Hatter"];
fn main() {
println!("Prefix: {:?}", PREFIX);
let num_of_vcpus = num_cpus::get();
let num_of_phycpus = num_cpus::get_physical();
println!("You have {} vCPUs, from {} phyCPUs", num_of_vcpus, num_of_phycpus);
let stop_flag = Arc::new(Mutex::new(false));
let mut handles = vec![];
for ind in 0..4 {
for ind in 0..num_of_phycpus {
println!("- Running task {} of {}", ind, num_of_phycpus);
let the_stop_flag = Arc::clone(&stop_flag);
let child = thread::spawn(move || {
run_one_task(ind, the_stop_flag);
@@ -37,7 +39,7 @@ fn run_one_task(ind: usize, the_stop_flag: Arc<Mutex<bool>>) {
let s = make_btc_address(&public_key);
if i % 10_000 == 0 {
if i % 1_000 == 0 {
if *the_stop_flag.lock().unwrap() {
return;
}