Skip to content

Commit

Permalink
add black-boxing, remove debugging assert
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Aug 8, 2024
1 parent 4331f1b commit e61d836
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions runtime-transaction/benches/process_compute_budget_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
system_instruction::{self},
transaction::{SanitizedTransaction, Transaction},
},
test::Bencher,
test::{black_box, Bencher},
};

const NUM_TRANSACTIONS_PER_ITER: usize = 1024;
Expand All @@ -33,10 +33,10 @@ fn bench_process_compute_budget_instructions_empty(bencher: &mut Bencher) {
let tx = build_sanitized_transaction(&Keypair::new(), &[]);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(
process_compute_budget_instructions(tx.message().program_instructions_iter())
.is_ok()
assert!(process_compute_budget_instructions(
black_box(tx.message()).program_instructions_iter()
)
.is_ok())
})
});
}
Expand All @@ -46,14 +46,13 @@ fn bench_process_compute_budget_instructions_non_builtins(bencher: &mut Bencher)
let ixs: Vec<_> = (0..4)
.map(|_| Instruction::new_with_bincode(DUMMY_PROGRAM_ID.parse().unwrap(), &0_u8, vec![]))
.collect();
assert_eq!(4, ixs.len());
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(
process_compute_budget_instructions(tx.message().program_instructions_iter())
.is_ok()
assert!(process_compute_budget_instructions(
black_box(tx.message()).program_instructions_iter()
)
.is_ok())
})
});
}
Expand All @@ -66,14 +65,13 @@ fn bench_process_compute_budget_instructions_compute_budgets(bencher: &mut Bench
ComputeBudgetInstruction::set_compute_unit_price(u64::MAX),
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
];
assert_eq!(4, ixs.len());
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(
process_compute_budget_instructions(tx.message().program_instructions_iter())
.is_ok()
assert!(process_compute_budget_instructions(
black_box(tx.message()).program_instructions_iter()
)
.is_ok())
})
});
}
Expand All @@ -90,14 +88,13 @@ fn bench_process_compute_budget_instructions_builtins(bencher: &mut Bencher) {
),
Instruction::new_with_bincode(solana_sdk::loader_v4::id(), &0_u8, vec![]),
];
assert_eq!(4, ixs.len());
let tx = build_sanitized_transaction(&Keypair::new(), &ixs);
bencher.iter(|| {
(0..NUM_TRANSACTIONS_PER_ITER).for_each(|_| {
assert!(
process_compute_budget_instructions(tx.message().program_instructions_iter())
.is_ok()
assert!(process_compute_budget_instructions(
black_box(tx.message()).program_instructions_iter()
)
.is_ok())
})
});
}
Expand All @@ -114,15 +111,14 @@ fn bench_process_compute_budget_instructions_mixed(bencher: &mut Bencher) {
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(u32::MAX),
system_instruction::transfer(&payer_keypair.pubkey(), &Pubkey::new_unique(), 1),
]);
assert_eq!(133, ixs.len());
let tx = build_sanitized_transaction(&payer_keypair, &ixs);

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

0 comments on commit e61d836

Please sign in to comment.