Skip to content

Commit

Permalink
customize criterion to use Throughput option
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Aug 13, 2024
1 parent d2b0134 commit 4274f6c
Showing 1 changed file with 95 additions and 81 deletions.
176 changes: 95 additions & 81 deletions runtime-transaction/benches/process_compute_budget_instructions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
criterion::{black_box, criterion_group, criterion_main, Criterion},
criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput},
solana_runtime_transaction::instructions_processor::process_compute_budget_instructions,
solana_sdk::{
compute_budget::ComputeBudgetInstruction,
Expand Down Expand Up @@ -27,104 +27,118 @@ fn build_sanitized_transaction(
}

fn bench_process_compute_budget_instructions_empty(c: &mut Criterion) {
c.bench_function("No instructions", |bencher| {
let tx = build_sanitized_transaction(&Keypair::new(), &[]);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
c.benchmark_group(format!("bench_size_{NUM_TRANSACTIONS_PER_ITER}"))
.throughput(Throughput::Elements(NUM_TRANSACTIONS_PER_ITER as u64))
.bench_function("No instructions", |bencher| {
let tx = build_sanitized_transaction(&Keypair::new(), &[]);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
});
});
});
}

fn bench_process_compute_budget_instructions_no_builtins(c: &mut Criterion) {
c.bench_function("No builtins", |bencher| {
let ixs: Vec<_> = (0..4)
.map(|_| Instruction::new_with_bincode(DUMMY_PROGRAM_ID.parse().unwrap(), &(), vec![]))
.collect();
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
c.benchmark_group(format!("bench_size_{NUM_TRANSACTIONS_PER_ITER}"))
.throughput(Throughput::Elements(NUM_TRANSACTIONS_PER_ITER as u64))
.bench_function("No builtins", |bencher| {
let ixs: Vec<_> = (0..4)
.map(|_| {
Instruction::new_with_bincode(DUMMY_PROGRAM_ID.parse().unwrap(), &(), vec![])
})
.collect();
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
});
});
});
}

fn bench_process_compute_budget_instructions_compute_budgets(c: &mut Criterion) {
c.bench_function("Only compute-budget instructions", |bencher| {
let ixs = vec![
ComputeBudgetInstruction::request_heap_frame(40 * 1024),
ComputeBudgetInstruction::set_compute_unit_limit(u32::MAX),
ComputeBudgetInstruction::set_compute_unit_price(u64::MAX),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
];
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
c.benchmark_group(format!("bench_size_{NUM_TRANSACTIONS_PER_ITER}"))
.throughput(Throughput::Elements(NUM_TRANSACTIONS_PER_ITER as u64))
.bench_function("Only compute-budget instructions", |bencher| {
let ixs = vec![
ComputeBudgetInstruction::request_heap_frame(40 * 1024),
ComputeBudgetInstruction::set_compute_unit_limit(u32::MAX),
ComputeBudgetInstruction::set_compute_unit_price(u64::MAX),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
];
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
});
});
});
}

fn bench_process_compute_budget_instructions_builtins(c: &mut Criterion) {
c.bench_function("Only builtins", |bencher| {
let ixs = vec![
Instruction::new_with_bincode(solana_sdk::bpf_loader::id(), &(), vec![]),
Instruction::new_with_bincode(solana_sdk::secp256k1_program::id(), &(), vec![]),
Instruction::new_with_bincode(
solana_sdk::address_lookup_table::program::id(),
&(),
vec![],
),
Instruction::new_with_bincode(solana_sdk::loader_v4::id(), &(), vec![]),
];
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
c.benchmark_group(format!("bench_size_{NUM_TRANSACTIONS_PER_ITER}"))
.throughput(Throughput::Elements(NUM_TRANSACTIONS_PER_ITER as u64))
.bench_function("Only builtins", |bencher| {
let ixs = vec![
Instruction::new_with_bincode(solana_sdk::bpf_loader::id(), &(), vec![]),
Instruction::new_with_bincode(solana_sdk::secp256k1_program::id(), &(), vec![]),
Instruction::new_with_bincode(
solana_sdk::address_lookup_table::program::id(),
&(),
vec![],
),
Instruction::new_with_bincode(solana_sdk::loader_v4::id(), &(), vec![]),
];
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
});
});
});
}

fn bench_process_compute_budget_instructions_mixed(c: &mut Criterion) {
c.bench_function("Mixed instructions", |bencher| {
let payer_keypair = Keypair::new();
let mut ixs: Vec<_> = (0..128)
.map(|_| Instruction::new_with_bincode(DUMMY_PROGRAM_ID.parse().unwrap(), &(), vec![]))
.collect();
ixs.extend(vec![
ComputeBudgetInstruction::request_heap_frame(40 * 1024),
ComputeBudgetInstruction::set_compute_unit_limit(u32::MAX),
ComputeBudgetInstruction::set_compute_unit_price(u64::MAX),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
system_instruction::transfer(&payer_keypair.pubkey(), &Pubkey::new_unique(), 1),
]);
let tx = build_sanitized_transaction(&payer_keypair, &ixs);
c.benchmark_group(format!("bench_size_{NUM_TRANSACTIONS_PER_ITER}"))
.throughput(Throughput::Elements(NUM_TRANSACTIONS_PER_ITER as u64))
.bench_function("Mixed instructions", |bencher| {
let payer_keypair = Keypair::new();
let mut ixs: Vec<_> = (0..128)
.map(|_| {
Instruction::new_with_bincode(DUMMY_PROGRAM_ID.parse().unwrap(), &(), vec![])
})
.collect();
ixs.extend(vec![
ComputeBudgetInstruction::request_heap_frame(40 * 1024),
ComputeBudgetInstruction::set_compute_unit_limit(u32::MAX),
ComputeBudgetInstruction::set_compute_unit_price(u64::MAX),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
system_instruction::transfer(&payer_keypair.pubkey(), &Pubkey::new_unique(), 1),
]);
let tx = build_sanitized_transaction(&payer_keypair, &ixs);

bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(process_compute_budget_instructions(black_box(
tx.message().program_instructions_iter()
))
.is_ok())
})
});
});
});
}

criterion_group!(
Expand Down

0 comments on commit 4274f6c

Please sign in to comment.