Skip to content

Commit

Permalink
Merge pull request #3 from waitfreemaxi/main
Browse files Browse the repository at this point in the history
add transfer benchmarks
  • Loading branch information
buffalojoec authored Jun 22, 2024
2 parents e861087 + d8dc218 commit da3b793
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ solana-program-runtime = { workspace = true }
solana-system-program = { workspace = true }
solana-sdk = { workspace = true }
solana-logger = "2.0.0"


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

[dev-dependencies]
criterion = "0.5.1"
65 changes: 65 additions & 0 deletions harness/benches/ips.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Benches Mollusk invocation (instructions per second)
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use mollusk::{result::Check, Mollusk};
use solana_sdk::{
account::AccountSharedData, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, system_instruction,
system_program,
};
use solana_system_program::system_processor::DEFAULT_COMPUTE_UNITS;

fn transfer_checked_unchecked(c: &mut Criterion) {
let sender = Pubkey::new_unique();
let recipient = Pubkey::new_unique();

let base_lamports = 100 * LAMPORTS_PER_SOL;
let transfer_amount = 1;

let instruction = system_instruction::transfer(&sender, &recipient, transfer_amount);
let accounts = vec![
(
sender,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
),
(
recipient,
AccountSharedData::new(base_lamports, 0, &system_program::id()),
),
];
let checks = vec![
Check::success(),
Check::compute_units(DEFAULT_COMPUTE_UNITS),
Check::account(&sender)
.lamports(base_lamports - transfer_amount)
.build(),
Check::account(&recipient)
.lamports(base_lamports + transfer_amount)
.build(),
];

// No logs for bench
let mollusk = Mollusk::default();
solana_logger::setup_with("");

// Create transfers group with elements/second
let mut g = c.benchmark_group("transfers");
g.throughput(Throughput::Elements(1));

// Bench transfer with post-execution checks
g.bench_function("transfer_checked", |b| {
b.iter(|| {
mollusk.process_and_validate_instruction(&instruction, accounts.clone(), &checks);
})
});

// Bench transfer without post-execution checks
g.bench_function("transfer_unchecked", |b| {
b.iter(|| {
mollusk.process_instruction(&instruction, accounts.clone());
})
});

g.finish();
}

criterion_group!(transfers, transfer_checked_unchecked);
criterion_main!(transfers);

0 comments on commit da3b793

Please sign in to comment.