Skip to content

Commit

Permalink
Add a quick and dirty bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Czabaniuk committed May 20, 2021
1 parent 83f2de7 commit f039786
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions ledger/benches/u8_vec_resize.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<u8>> = (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<Vec<u8>> = (0..NUM_VECS)
.map(|_| {
vec![VAL; 500]
})
.collect();
for i in 0..NUM_VECS {
vecs[i].resize(SHRED_PAYLOAD_SIZE, 0);
}
});
}

0 comments on commit f039786

Please sign in to comment.