Skip to content

Commit

Permalink
chore: Document how to run concurrent/single account seed comp
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Jan 9, 2025
1 parent 2b97767 commit 0af0888
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions objects/benches/account_seed.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, Criterion};
use miden_objects::{
accounts::{AccountId, AccountIdVersion, AccountStorageMode, AccountType},
Digest,
};
use rand::{Rng, SeedableRng};

/// Running this benchmark with --no-default-features will use the single-threaded account seed
/// computation.
///
/// Passing --features concurrent will use the multi-threaded account seed computation.
fn grind_account_seed(c: &mut Criterion) {
let mut group = c.benchmark_group("grind-seed");
// Increase measurement time (= target time) from the default 5s as suggested by criterion
// during a run.
group.measurement_time(Duration::from_secs(20));

let init_seed = [
1, 18, 222, 14, 56, 94, 222, 213, 12, 57, 86, 1, 22, 34, 187, 100, 210, 1, 18, 222, 14, 56,
94, 43, 213, 12, 57, 86, 1, 22, 34, 187,
];
// Use an rng to ensure we're starting from different seeds for each iteration.
let mut rng = rand_xoshiro::Xoshiro256PlusPlus::from_seed(init_seed);

c.bench_function("Grind regular on-chain account seed", |bench| {
group.bench_function("Grind regular on-chain account seed", |bench| {
bench.iter(|| {
AccountId::compute_account_seed(
init_seed,
rng.gen(),
AccountType::RegularAccountImmutableCode,
AccountStorageMode::Public,
AccountIdVersion::VERSION_0,
Expand All @@ -24,10 +38,12 @@ fn grind_account_seed(c: &mut Criterion) {
})
});

c.bench_function("Grind fungible faucet on-chain account seed", |bench| {
// Reinitialize the RNG.
let mut rng = rand_xoshiro::Xoshiro256PlusPlus::from_seed(init_seed);
group.bench_function("Grind fungible faucet on-chain account seed", |bench| {
bench.iter(|| {
AccountId::compute_account_seed(
init_seed,
rng.gen(),
AccountType::FungibleFaucet,
AccountStorageMode::Public,
AccountIdVersion::VERSION_0,
Expand All @@ -37,6 +53,8 @@ fn grind_account_seed(c: &mut Criterion) {
)
})
});

group.finish();
}

criterion_group!(account_seed, grind_account_seed);
Expand Down

0 comments on commit 0af0888

Please sign in to comment.