Skip to content

Commit

Permalink
Rayon 10x speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Nov 13, 2023
1 parent aa2b0c7 commit f3a3f47
Show file tree
Hide file tree
Showing 15 changed files with 1,380 additions and 418 deletions.
851 changes: 848 additions & 3 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rad"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -23,17 +23,28 @@ itertools = "0.11.0"
unindent = "0.2.3"
const_format = "0.2.32"
primitive-types = "0.12.2"
default-args = "1.0.0"
async-std = { version = "1.12.0", features = ["attributes"] }
futures = "0.3.29"
num-iter = "0.1.43"
rayon = "1.8.0"

[dev-dependencies]
default-args = "1.0.0"
criterion = "0.5.1"

[[bin]]
name = "rad"
test = false

[[bench]]
name = "my_benchmark"
harness = false

[profile.test]
opt-level = 3
debug = true
debug-assertions = false
panic = "abort"
overflow-checks = false
lto = false
incremental = false
Expand All @@ -45,7 +56,10 @@ opt-level = 3
codegen-units = 1
panic = "abort"
strip = "symbols"
debug = false
lto = true
debug-assertions = false
overflow-checks = false
debug = true

[profile.bench]
debug = true
28 changes: 28 additions & 0 deletions benches/my_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::time::Duration;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rad::{
find_par::par_find,
input,
params::{Bip39WordCount, MAX_INDEX},
run_config::RunConfig,
};

pub fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("benchmarking");
group
.sample_size(10)
.measurement_time(Duration::from_secs(200)); // target "xyz" takes ~150 sec on Macbook Pro M2
group.bench_function("benchy", |b| {
b.iter(|| {
black_box(par_find(
input!("p").unwrap(),
RunConfig::new(false, 0, false, false),
))
})
});
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
48 changes: 13 additions & 35 deletions src/bin/rad.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use clap::{Parser, Subcommand};
use rad::file_reader::suffixes_from_file;
use rad::find::{find_all, find_n};
use rad::find_par::par_find;
use rad::info::{INFO_DONATION_ADDR_ONLY, INFO_WITH_DONATION_QR};
use rad::params::{Bip39WordCount, BruteForceInput};
use rad::run_config::RunConfig;
use std::time::SystemTime;

#[derive(Parser)]
#[command(name = "rad", version)]
Expand All @@ -22,29 +23,6 @@ struct Cli {
#[command(subcommand)]
target_suffixes: TargetSuffixes,

/// If we want to continue searching for more vanity accounts for a given
/// target after we have found one. If `false` is passed, we will remove
/// the target after first account is found (better performance). If `true`,
/// the program will find multiple matches per target.
#[arg(short = 'c', long, default_value_t = false)]
multi_match_per_target: bool,

/// How many matches PER MMEMONIC we will search for until program exits,
/// `0` means run forver. Any other value means stop program after than
/// many vanity accounts have been found.
#[arg(short = 'n', long, default_value_t = 0)]
matches_per_mnemonic: usize,

/// How often you want the program to print any progress, use `0` to not print any progress.
/// Since finding accounts can take a very long time if 6 character long targets are used
/// it can be nice to see some kind of progress, you typicall want this to be a high number
/// like 10k - 1M, depending on how fast your machine is.
///
/// If you are piping the output to a pager, e.g. `less` you typicall want to specify `0` to
/// this argument, so not have to scroll meaningless progress prints.
#[arg(short = 'p', long = "pulse", default_value_t = 10000)]
print_pulse: u32,

/// The number of indices to test per mnemonic,
/// is used, which is convenient if you find a lot of nice vanity account using the same
/// mnemonic, you have less number of mnemonics you need to manage.
Expand Down Expand Up @@ -74,20 +52,20 @@ fn main() {
let input = BruteForceInput::new_splitting_targets(
&csv_string,
cli.end_index,
cli.multi_match_per_target,
true,
Bip39WordCount::Twelve,
Option::None,
None,
)
.expect("Valid input");

let run_config = RunConfig::new(cli.print_pulse);
let matches_per_mnemonic = cli.matches_per_mnemonic;
let run_config = RunConfig::new(true, 0, true, true);
println!("{}", INFO_WITH_DONATION_QR);
match matches_per_mnemonic {
0 => find_all(input, run_config),
_ => {
find_n(cli.matches_per_mnemonic, input, run_config);
()
}
}
let now = SystemTime::now();
let vec = par_find(input, run_config);
let time_elapsed = now.elapsed().unwrap();
println!(
"✅ Exiting program, ran for '{}' ms, found #{} results",
time_elapsed.as_millis(),
vec.len()
);
}
138 changes: 0 additions & 138 deletions src/find.rs

This file was deleted.

Loading

0 comments on commit f3a3f47

Please sign in to comment.