forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add bench for cost-tracker * use `ahash` in cost_tracker
- Loading branch information
1 parent
5a9906e
commit 8a55087
Showing
5 changed files
with
94 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,81 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
use { | ||
itertools::Itertools, | ||
solana_cost_model::{ | ||
cost_tracker::CostTracker, | ||
transaction_cost::{TransactionCost, UsageCostDetails}, | ||
}, | ||
solana_sdk::pubkey::Pubkey, | ||
test::Bencher, | ||
}; | ||
|
||
struct BenchSetup { | ||
cost_tracker: CostTracker, | ||
tx_costs: Vec<TransactionCost>, | ||
} | ||
|
||
fn setup(num_transactions: usize, contentious_transactions: bool) -> BenchSetup { | ||
let mut cost_tracker = CostTracker::default(); | ||
// set cost_tracker with max limits to stretch testing | ||
cost_tracker.set_limits(u64::MAX, u64::MAX, u64::MAX); | ||
|
||
let max_accounts_per_tx = 128; | ||
let pubkey = Pubkey::new_unique(); | ||
let tx_costs = (0..num_transactions) | ||
.map(|_| { | ||
let mut usage_cost_details = UsageCostDetails::default(); | ||
(0..max_accounts_per_tx).for_each(|_| { | ||
let writable_account_key = if contentious_transactions { | ||
pubkey | ||
} else { | ||
Pubkey::new_unique() | ||
}; | ||
usage_cost_details | ||
.writable_accounts | ||
.push(writable_account_key) | ||
}); | ||
usage_cost_details.programs_execution_cost = 9999; | ||
TransactionCost::Transaction(usage_cost_details) | ||
}) | ||
.collect_vec(); | ||
|
||
BenchSetup { | ||
cost_tracker, | ||
tx_costs, | ||
} | ||
} | ||
|
||
#[bench] | ||
fn bench_cost_tracker_non_contentious_transaction(bencher: &mut Bencher) { | ||
let BenchSetup { | ||
mut cost_tracker, | ||
tx_costs, | ||
} = setup(1024, false); | ||
|
||
bencher.iter(|| { | ||
for tx_cost in tx_costs.iter() { | ||
if cost_tracker.try_add(tx_cost).is_err() { | ||
break; | ||
} // stop when hit limits | ||
cost_tracker.update_execution_cost(tx_cost, 0); // update execution cost down to zero | ||
} | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_cost_tracker_contentious_transaction(bencher: &mut Bencher) { | ||
let BenchSetup { | ||
mut cost_tracker, | ||
tx_costs, | ||
} = setup(1024, true); | ||
|
||
bencher.iter(|| { | ||
for tx_cost in tx_costs.iter() { | ||
if cost_tracker.try_add(tx_cost).is_err() { | ||
break; | ||
} // stop when hit limits | ||
cost_tracker.update_execution_cost(tx_cost, 0); // update execution cost down to zero | ||
} | ||
}); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.