2019-01-07 08:38:19 -08:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
2019-10-25 21:47:16 -07:00
|
|
|
use log::*;
|
2020-03-31 10:07:38 -07:00
|
|
|
use solana_runtime::{message_processor::PreAccount, rent_collector::RentCollector};
|
2019-10-25 21:47:16 -07:00
|
|
|
use solana_sdk::{account::Account, pubkey::Pubkey};
|
2019-01-07 08:38:19 -08:00
|
|
|
use test::Bencher;
|
|
|
|
|
2019-10-25 21:47:16 -07:00
|
|
|
#[bench]
|
2019-11-18 14:01:14 -08:00
|
|
|
fn bench_verify_account_changes_data(bencher: &mut Bencher) {
|
2019-10-25 21:47:16 -07:00
|
|
|
solana_logger::setup();
|
|
|
|
|
|
|
|
let owner = Pubkey::new_rand();
|
|
|
|
let non_owner = Pubkey::new_rand();
|
2020-04-18 17:04:13 -07:00
|
|
|
let pre = PreAccount::new(&Account::new(0, BUFSIZE, &owner), &owner, true);
|
2019-10-25 21:47:16 -07:00
|
|
|
let post = Account::new(0, BUFSIZE, &owner);
|
2020-03-31 10:07:38 -07:00
|
|
|
assert_eq!(pre.verify(&owner, &RentCollector::default(), &post), Ok(()));
|
2019-10-25 21:47:16 -07:00
|
|
|
|
|
|
|
// this one should be faster
|
|
|
|
bencher.iter(|| {
|
2020-03-31 10:07:38 -07:00
|
|
|
pre.verify(&owner, &RentCollector::default(), &post)
|
|
|
|
.unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
|
|
|
let summary = bencher.bench(|_bencher| {}).unwrap();
|
|
|
|
info!("data no change by owner: {} ns/iter", summary.median);
|
|
|
|
|
2020-04-18 17:04:13 -07:00
|
|
|
let pre = PreAccount::new(&Account::new(0, BUFSIZE, &owner), &non_owner, true);
|
2019-11-05 10:57:32 -08:00
|
|
|
match pre.data {
|
|
|
|
Some(ref data) => bencher.iter(|| *data == post.data),
|
|
|
|
None => panic!("No data!"),
|
|
|
|
}
|
|
|
|
let summary = bencher.bench(|_bencher| {}).unwrap();
|
|
|
|
info!("data compare {} ns/iter", summary.median);
|
2019-10-25 21:47:16 -07:00
|
|
|
bencher.iter(|| {
|
2020-03-31 10:07:38 -07:00
|
|
|
pre.verify(&non_owner, &RentCollector::default(), &post)
|
|
|
|
.unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
|
|
|
let summary = bencher.bench(|_bencher| {}).unwrap();
|
|
|
|
info!("data no change by non owner: {} ns/iter", summary.median);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BUFSIZE: usize = 1024 * 1024 + 127;
|
|
|
|
static BUF0: [u8; BUFSIZE] = [0; BUFSIZE];
|
|
|
|
static BUF1: [u8; BUFSIZE] = [1; BUFSIZE];
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_is_zeroed(bencher: &mut Bencher) {
|
|
|
|
bencher.iter(|| {
|
2020-02-21 11:30:00 -08:00
|
|
|
PreAccount::is_zeroed(&BUF0);
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_is_zeroed_not(bencher: &mut Bencher) {
|
|
|
|
bencher.iter(|| {
|
2020-02-21 11:30:00 -08:00
|
|
|
PreAccount::is_zeroed(&BUF1);
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_is_zeroed_by_iter(bencher: &mut Bencher) {
|
|
|
|
bencher.iter(|| BUF0.iter().all(|item| *item == 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_is_zeroed_not_by_iter(bencher: &mut Bencher) {
|
|
|
|
bencher.iter(|| BUF1.iter().all(|item| *item == 0));
|
|
|
|
}
|