From f039786f3177617d1ed0f6d598a8b435621850b8 Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Wed, 19 May 2021 15:51:54 -0500 Subject: [PATCH] Add a quick and dirty bench --- ledger/benches/u8_vec_resize.rs | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 ledger/benches/u8_vec_resize.rs diff --git a/ledger/benches/u8_vec_resize.rs b/ledger/benches/u8_vec_resize.rs new file mode 100644 index 00000000000000..2ec509d532f985 --- /dev/null +++ b/ledger/benches/u8_vec_resize.rs @@ -0,0 +1,93 @@ +#![feature(test)] +extern crate test; + +use solana_ledger::shred::SHRED_PAYLOAD_SIZE; +use test::Bencher; + +const VAL: u8 = 225; +const NUM_VECS: usize = 1000; + +#[bench] +fn bench_allocate_vec_250(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 250]; + }); +} + +#[bench] +fn bench_allocate_and_resize_vec_250(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 250]; + vec.resize(SHRED_PAYLOAD_SIZE, 0); + }); +} + +#[bench] +fn bench_allocate_vec_500(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 500]; + }); +} + +#[bench] +fn bench_allocate_and_resize_vec_500(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 500]; + vec.resize(SHRED_PAYLOAD_SIZE, 0); + }); +} + +#[bench] +fn bench_allocate_vec_750(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 750]; + }); +} + +#[bench] +fn bench_allocate_and_resize_vec_750(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 750]; + vec.resize(SHRED_PAYLOAD_SIZE, 0); + }); +} + +#[bench] +fn bench_allocate_vec_1000(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 1000]; + }); +} + +#[bench] +fn bench_allocate_and_resize_vec_1000(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vec = vec![VAL; 1000]; + vec.resize(SHRED_PAYLOAD_SIZE, 0); + }); +} + +#[bench] +fn bench_allocate_1000_vec_500(bencher: &mut Bencher) { + bencher.iter(|| { + let vecs: Vec> = (0..NUM_VECS) + .map(|_| { + vec![VAL; 500] + }) + .collect(); + }); +} + +#[bench] +fn bench_allocate_and_resize_1000_vec_500(bencher: &mut Bencher) { + bencher.iter(|| { + let mut vecs: Vec> = (0..NUM_VECS) + .map(|_| { + vec![VAL; 500] + }) + .collect(); + for i in 0..NUM_VECS { + vecs[i].resize(SHRED_PAYLOAD_SIZE, 0); + } + }); +}