2019-01-07 08:38:19 -08:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
log::*,
|
|
|
|
solana_program_runtime::{pre_account::PreAccount, timings::ExecuteDetailsTimings},
|
|
|
|
solana_sdk::{account::AccountSharedData, pubkey, rent::Rent},
|
|
|
|
test::Bencher,
|
|
|
|
};
|
2019-01-07 08:38:19 -08:00
|
|
|
|
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();
|
|
|
|
|
2020-10-19 12:23:14 -07:00
|
|
|
let owner = pubkey::new_rand();
|
|
|
|
let non_owner = pubkey::new_rand();
|
2020-04-28 14:33:56 -07:00
|
|
|
let pre = PreAccount::new(
|
2020-10-19 12:23:14 -07:00
|
|
|
&pubkey::new_rand(),
|
2021-12-14 06:44:31 -08:00
|
|
|
AccountSharedData::new(0, BUFSIZE, &owner),
|
2020-04-28 14:33:56 -07:00
|
|
|
);
|
2021-03-09 13:06:07 -08:00
|
|
|
let post = AccountSharedData::new(0, BUFSIZE, &owner);
|
2021-01-22 15:28:01 -08:00
|
|
|
assert_eq!(
|
2021-03-03 15:07:45 -08:00
|
|
|
pre.verify(
|
|
|
|
&owner,
|
2021-03-10 09:48:41 -08:00
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
&Rent::default(),
|
|
|
|
&post,
|
2021-03-31 16:02:59 -07:00
|
|
|
&mut ExecuteDetailsTimings::default(),
|
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
),
|
2021-01-22 15:28:01 -08:00
|
|
|
Ok(())
|
|
|
|
);
|
2019-10-25 21:47:16 -07:00
|
|
|
|
|
|
|
// this one should be faster
|
|
|
|
bencher.iter(|| {
|
2021-03-03 15:07:45 -08:00
|
|
|
pre.verify(
|
|
|
|
&owner,
|
2021-03-10 09:48:41 -08:00
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
&Rent::default(),
|
|
|
|
&post,
|
|
|
|
&mut ExecuteDetailsTimings::default(),
|
2021-03-31 16:02:59 -07:00
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
)
|
|
|
|
.unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
2022-11-09 14:15:03 -08:00
|
|
|
let summary = bencher.bench(|_bencher| Ok(())).unwrap().unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
info!("data no change by owner: {} ns/iter", summary.median);
|
|
|
|
|
2020-04-28 14:33:56 -07:00
|
|
|
let pre_data = vec![BUFSIZE];
|
|
|
|
let post_data = vec![BUFSIZE];
|
|
|
|
bencher.iter(|| pre_data == post_data);
|
2022-11-09 14:15:03 -08:00
|
|
|
let summary = bencher.bench(|_bencher| Ok(())).unwrap().unwrap();
|
2019-11-05 10:57:32 -08:00
|
|
|
info!("data compare {} ns/iter", summary.median);
|
2020-04-28 14:33:56 -07:00
|
|
|
|
|
|
|
let pre = PreAccount::new(
|
2020-10-19 12:23:14 -07:00
|
|
|
&pubkey::new_rand(),
|
2021-12-14 06:44:31 -08:00
|
|
|
AccountSharedData::new(0, BUFSIZE, &owner),
|
2020-04-28 14:33:56 -07:00
|
|
|
);
|
2019-10-25 21:47:16 -07:00
|
|
|
bencher.iter(|| {
|
2021-03-03 15:07:45 -08:00
|
|
|
pre.verify(
|
|
|
|
&non_owner,
|
2021-03-10 09:48:41 -08:00
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
&Rent::default(),
|
|
|
|
&post,
|
|
|
|
&mut ExecuteDetailsTimings::default(),
|
2021-03-31 16:02:59 -07:00
|
|
|
false,
|
2021-03-03 15:07:45 -08:00
|
|
|
)
|
|
|
|
.unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
});
|
2022-11-09 14:15:03 -08:00
|
|
|
let summary = bencher.bench(|_bencher| Ok(())).unwrap().unwrap();
|
2019-10-25 21:47:16 -07:00
|
|
|
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));
|
|
|
|
}
|