diff --git a/benches/bench.rs b/benches/bench.rs index 45c9979..35a15a2 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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) { @@ -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]); } @@ -46,6 +51,53 @@ fn vec_u_vn_s_copy(bencher: &mut Bencher) { ); } +#[bench] +fn empty_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![(); 1024]); +} +#[bench] +fn u64_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![0u64; 1024]); +} +#[bench] +fn u32x2_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![(0u32, 0u32); 1024]); +} +#[bench] +fn u8_u64_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![(0u8, 0u64); 512]); +} +#[bench] +fn str10_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec!["grawwwwrr!"; 1024]); +} +#[bench] +fn str100_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec!["grawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrrgrawwwwrr!!!!!!!!!grawwwwrr!"; 1024]); +} +#[bench] +fn string10_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![format!("grawwwwrr!"); 1024]); +} +#[bench] +fn string20_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>(bencher, vec![format!("grawwwwrr!!!!!!!!!!!"); 512]); +} +#[bench] +fn vec_u_s_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, _>( + bencher, + vec![vec![(0u64, "grawwwwrr!".to_string()); 32]; 32], + ); +} +#[bench] +fn vec_u_vn_s_copy_region(bencher: &mut Bencher) { + _bench_copy_region::, 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]); @@ -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]); } @@ -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]); } @@ -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]); } @@ -178,6 +242,21 @@ where }); } +fn _bench_copy_region(bencher: &mut Bencher, record: T) +where + for<'a> &'a T: CopyOnto, +{ + // prepare encoded data for bencher.bytes + let mut arena = FlatStack::::default(); + + bencher.iter(|| { + arena.clear(); + for _ in 0..1024 { + arena.copy(&record); + } + }); +} + fn _bench_clone(bencher: &mut Bencher, record: T) { // prepare encoded data for bencher.bytes let mut arena = Vec::new();