-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from waitfreemaxi/main
add transfer benchmarks
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |