Skip to content

Commit

Permalink
Benchmark updates
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru committed Feb 8, 2024
1 parent b6554e3 commit 30366af
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

extern crate test;

use flatcontainer::{Containerized, CopyOnto, FlatStack, ReserveItems};
use flatcontainer::{Containerized, CopyOnto, CopyRegion, FlatStack, MirrorRegion, Region, ReserveItems, SliceRegion, StringRegion};
use test::Bencher;
use flatcontainer::impls::tuple::TupleABCRegion;

#[bench]
fn empty_copy(bencher: &mut Bencher) {
Expand All @@ -24,6 +25,10 @@ fn u8_u64_copy(bencher: &mut Bencher) {
_bench_copy(bencher, vec![(0u8, 0u64); 512]);
}
#[bench]
fn str10_copy(bencher: &mut Bencher) {
_bench_copy(bencher, vec!["grawwwwrr!"; 1024]);
}
#[bench]
fn string10_copy(bencher: &mut Bencher) {
_bench_copy(bencher, vec![format!("grawwwwrr!"); 1024]);
}
Expand All @@ -46,6 +51,53 @@ fn vec_u_vn_s_copy(bencher: &mut Bencher) {
);
}

#[bench]
fn empty_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec![(); 1024]);
}
#[bench]
fn u64_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec![0u64; 1024]);
}
#[bench]
fn u32x2_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec![(0u32, 0u32); 1024]);
}
#[bench]
fn u8_u64_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec![(0u8, 0u64); 512]);
}
#[bench]
fn str10_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec!["grawwwwrr!"; 1024]);
}
#[bench]
fn str100_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<CopyRegion<_>, _>(bencher, vec!["grawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrr!!!!!!!!!grawwwwrr!"; 1024]);
}
#[bench]
fn string10_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<_>, _>(bencher, vec![format!("grawwwwrr!"); 1024]);
}
#[bench]
fn string20_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<_>, _>(bencher, vec![format!("grawwwwrr!!!!!!!!!!!"); 512]);
}
#[bench]
fn vec_u_s_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<_>, _>(
bencher,
vec![vec![(0u64, "grawwwwrr!".to_string()); 32]; 32],
);
}
#[bench]
fn vec_u_vn_s_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<SliceRegion<TupleABCRegion<MirrorRegion<_>, CopyRegion<_>, StringRegion>>>, _>(
bencher,
vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
);
}

#[bench]
fn empty_clone(bencher: &mut Bencher) {
_bench_clone(bencher, vec![(); 1024]);
Expand All @@ -63,6 +115,10 @@ fn u8_u64_clone(bencher: &mut Bencher) {
_bench_clone(bencher, vec![(0u8, 0u64); 512]);
}
#[bench]
fn str10_clone(bencher: &mut Bencher) {
_bench_clone(bencher, vec!["grawwwwrr!"; 1024]);
}
#[bench]
fn string10_clone(bencher: &mut Bencher) {
_bench_clone(bencher, vec![format!("grawwwwrr!"); 1024]);
}
Expand Down Expand Up @@ -102,6 +158,10 @@ fn u8_u64_realloc(bencher: &mut Bencher) {
_bench_realloc(bencher, vec![(0u8, 0u64); 512]);
}
#[bench]
fn str10_realloc(bencher: &mut Bencher) {
_bench_realloc(bencher, vec!["grawwwwrr!"; 1024]);
}
#[bench]
fn string10_realloc(bencher: &mut Bencher) {
_bench_realloc(bencher, vec![format!("grawwwwrr!"); 1024]);
}
Expand Down Expand Up @@ -141,6 +201,10 @@ fn u8_u64_prealloc(bencher: &mut Bencher) {
_bench_prealloc(bencher, vec![(0u8, 0u64); 512]);
}
#[bench]
fn str10_prealloc(bencher: &mut Bencher) {
_bench_prealloc(bencher, vec!["grawwwwrr!"; 1024]);
}
#[bench]
fn string10_prealloc(bencher: &mut Bencher) {
_bench_prealloc(bencher, vec![format!("grawwwwrr!"); 1024]);
}
Expand Down Expand Up @@ -178,6 +242,21 @@ where
});
}

fn _bench_copy_region<R: Region, T>(bencher: &mut Bencher, record: T)
where
for<'a> &'a T: CopyOnto<R>,
{
// prepare encoded data for bencher.bytes
let mut arena = FlatStack::<R>::default();

bencher.iter(|| {
arena.clear();
for _ in 0..1024 {
arena.copy(&record);
}
});
}

fn _bench_clone<T: Containerized + Eq + Clone>(bencher: &mut Bencher, record: T) {
// prepare encoded data for bencher.bytes
let mut arena = Vec::new();
Expand Down

0 comments on commit 30366af

Please sign in to comment.