forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ahash for BUILTIN_INSTRUCTION_COSTS (#2329)
* Add bench tests for ahash vs hash * Use ahash for BUILTIN_INSTRUCTION_COSTS Fixes: #2196
- Loading branch information
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
use { | ||
rand::Rng, | ||
solana_cost_model::block_cost_limits::BUILTIN_INSTRUCTION_COSTS, | ||
solana_sdk::{ | ||
address_lookup_table, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, | ||
compute_budget, ed25519_program, loader_v4, pubkey::Pubkey, secp256k1_program, | ||
}, | ||
test::Bencher, | ||
}; | ||
|
||
struct BenchSetup { | ||
pubkeys: [Pubkey; 12], | ||
} | ||
|
||
const NUM_TRANSACTIONS_PER_ITER: usize = 1024; | ||
const DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT: u32 = 200_000; | ||
|
||
fn setup() -> BenchSetup { | ||
let pubkeys: [Pubkey; 12] = [ | ||
solana_stake_program::id(), | ||
solana_config_program::id(), | ||
solana_vote_program::id(), | ||
solana_system_program::id(), | ||
compute_budget::id(), | ||
address_lookup_table::program::id(), | ||
bpf_loader_upgradeable::id(), | ||
bpf_loader_deprecated::id(), | ||
bpf_loader::id(), | ||
loader_v4::id(), | ||
secp256k1_program::id(), | ||
ed25519_program::id(), | ||
]; | ||
|
||
BenchSetup { pubkeys } | ||
} | ||
|
||
#[bench] | ||
fn bench_hash_find(bencher: &mut Bencher) { | ||
let BenchSetup { pubkeys } = setup(); | ||
|
||
bencher.iter(|| { | ||
for _t in 0..NUM_TRANSACTIONS_PER_ITER { | ||
let idx = rand::thread_rng().gen_range(0..pubkeys.len()); | ||
let ix_execution_cost = | ||
if let Some(builtin_cost) = BUILTIN_INSTRUCTION_COSTS.get(&pubkeys[idx]) { | ||
*builtin_cost | ||
} else { | ||
u64::from(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT) | ||
}; | ||
assert!(ix_execution_cost != DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64); | ||
} | ||
}); | ||
} |
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