Files
solana/sdk/benches/serialize_instructions.rs
Tyera Eulberg 9b6ec0b6d5 v1.6: Restore ability for programs to upgrade themselves (#20263)
* Make helper associated fn

* Add feature definition

* Restore program-id write lock when upgradeable loader is present; restore bpf upgrade-self test

* Remove spurious comment
2021-09-27 22:29:59 +00:00

66 lines
2.0 KiB
Rust

#![feature(test)]
extern crate test;
use bincode::{deserialize, serialize};
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::message::Message;
use solana_sdk::pubkey;
use solana_sdk::sysvar::instructions;
use test::Bencher;
const RESTORE_WRITE_LOCK_WHEN_UPGRADEABLE: bool = true;
fn make_instructions() -> Vec<Instruction> {
let meta = AccountMeta::new(pubkey::new_rand(), false);
let inst = Instruction::new_with_bincode(pubkey::new_rand(), &[0; 10], vec![meta; 4]);
vec![inst; 4]
}
#[bench]
fn bench_bincode_instruction_serialize(b: &mut Bencher) {
let instructions = make_instructions();
b.iter(|| {
test::black_box(serialize(&instructions).unwrap());
});
}
#[bench]
fn bench_manual_instruction_serialize(b: &mut Bencher) {
let instructions = make_instructions();
let message = Message::new(&instructions, None);
b.iter(|| {
test::black_box(message.serialize_instructions(RESTORE_WRITE_LOCK_WHEN_UPGRADEABLE));
});
}
#[bench]
fn bench_bincode_instruction_deserialize(b: &mut Bencher) {
let instructions = make_instructions();
let serialized = serialize(&instructions).unwrap();
b.iter(|| {
test::black_box(deserialize::<Vec<Instruction>>(&serialized).unwrap());
});
}
#[bench]
fn bench_manual_instruction_deserialize(b: &mut Bencher) {
let instructions = make_instructions();
let message = Message::new(&instructions, None);
let serialized = message.serialize_instructions(RESTORE_WRITE_LOCK_WHEN_UPGRADEABLE);
b.iter(|| {
for i in 0..instructions.len() {
test::black_box(instructions::load_instruction_at(i, &serialized).unwrap());
}
});
}
#[bench]
fn bench_manual_instruction_deserialize_single(b: &mut Bencher) {
let instructions = make_instructions();
let message = Message::new(&instructions, None);
let serialized = message.serialize_instructions(RESTORE_WRITE_LOCK_WHEN_UPGRADEABLE);
b.iter(|| {
test::black_box(instructions::load_instruction_at(3, &serialized).unwrap());
});
}