11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4- //! Compare `FoR::encode `, which subtracts one reference from every value, against
5- //! `FoR::encode_chunked`, which subtracts a reference per 1024-element chunk .
4+ //! Benchmarks `FoR::encode_chunked `, which subtracts a reference per 1024-element chunk, with and
5+ //! without nulls .
66//!
77//! Every benchmark carries `#[cpu_features]`, so it is measured on each walltime CPU-feature leg
88//! rather than in simulation: the loops under test are auto-vectorized, so the build decides
@@ -17,15 +17,12 @@ use std::sync::LazyLock;
1717use divan:: Bencher ;
1818use divan:: counter:: ItemsCount ;
1919use mimalloc:: MiMalloc ;
20- use vortex_array:: ExecutionCtx ;
2120use vortex_array:: VortexSessionExecute ;
2221use vortex_array:: arrays:: PrimitiveArray ;
2322use vortex_array:: dtype:: NativePType ;
2423use vortex_array:: validity:: Validity ;
2524use vortex_buffer:: Buffer ;
26- use vortex_error:: VortexResult ;
2725use vortex_fastlanes:: FoR ;
28- use vortex_fastlanes:: FoRArray ;
2926use vortex_session:: VortexSession ;
3027
3128#[ global_allocator]
@@ -44,8 +41,6 @@ static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
4441/// Bytes of values per input array.
4542const INPUT_BYTES : & [ usize ] = & [ 512 * 1024 ] ;
4643
47- type Encode = fn ( PrimitiveArray , & mut ExecutionCtx ) -> VortexResult < FoRArray > ;
48-
4944/// Values that step up by 1000 every chunk, with a small spread within each chunk.
5045fn values < T : NativePType + TryFrom < usize > > ( len : usize ) -> Buffer < T > {
5146 ( 0 ..len)
@@ -65,42 +60,27 @@ fn validity(len: usize, nullable: bool) -> Validity {
6560 }
6661}
6762
68- fn run < T : NativePType + TryFrom < usize > > (
69- bencher : Bencher ,
70- bytes : usize ,
71- nullable : bool ,
72- encode : Encode ,
73- ) {
63+ fn run < T : NativePType + TryFrom < usize > > ( bencher : Bencher , bytes : usize , nullable : bool ) {
7464 let len = bytes / size_of :: < T > ( ) ;
7565 let buffer = values :: < T > ( len) ;
7666 let validity = validity ( len, nullable) ;
7767 bencher
7868 . counter ( ItemsCount :: new ( len) )
79- // A fresh array per iteration , so `FoR::encode` can't reuse a cached `Min` statistic .
69+ // `encode_chunked` takes the array by value , so each iteration encodes a fresh one .
8070 . with_inputs ( || PrimitiveArray :: new ( buffer. clone ( ) , validity. clone ( ) ) )
81- . bench_local_values ( |array| encode ( array, & mut SESSION . create_execution_ctx ( ) ) . unwrap ( ) ) ;
82- }
83-
84- #[ vortex_bench_support:: cpu_features]
85- #[ divan:: bench( types = [ i64 ] , args = INPUT_BYTES ) ]
86- fn encode < T : NativePType + TryFrom < usize > > ( bencher : Bencher , bytes : usize ) {
87- run :: < T > ( bencher, bytes, false , FoR :: encode) ;
71+ . bench_local_values ( |array| {
72+ FoR :: encode_chunked ( array, & mut SESSION . create_execution_ctx ( ) ) . unwrap ( )
73+ } ) ;
8874}
8975
9076#[ vortex_bench_support:: cpu_features]
9177#[ divan:: bench( types = [ i64 ] , args = INPUT_BYTES ) ]
9278fn encode_chunked < T : NativePType + TryFrom < usize > > ( bencher : Bencher , bytes : usize ) {
93- run :: < T > ( bencher, bytes, false , FoR :: encode_chunked) ;
94- }
95-
96- #[ vortex_bench_support:: cpu_features]
97- #[ divan:: bench( types = [ i64 ] , args = INPUT_BYTES ) ]
98- fn encode_nullable < T : NativePType + TryFrom < usize > > ( bencher : Bencher , bytes : usize ) {
99- run :: < T > ( bencher, bytes, true , FoR :: encode) ;
79+ run :: < T > ( bencher, bytes, false ) ;
10080}
10181
10282#[ vortex_bench_support:: cpu_features]
10383#[ divan:: bench( types = [ i64 ] , args = INPUT_BYTES ) ]
10484fn encode_chunked_nullable < T : NativePType + TryFrom < usize > > ( bencher : Bencher , bytes : usize ) {
105- run :: < T > ( bencher, bytes, true , FoR :: encode_chunked ) ;
85+ run :: < T > ( bencher, bytes, true ) ;
10686}
0 commit comments