@@ -28,6 +28,7 @@ use vortex_array::scalar_fn::unstable::row::RowVisitor;
2828use vortex_array:: scalar_fn:: unstable:: row:: execute_rows;
2929use vortex_error:: VortexExpect ;
3030use vortex_error:: VortexResult ;
31+ use vortex_error:: vortex_ensure;
3132use vortex_session:: VortexSession ;
3233use vortex_session:: registry:: CachedId ;
3334
@@ -87,6 +88,9 @@ impl BenchPrimitive for i64 {
8788#[ derive( Clone ) ]
8889struct InfallibleBool < T > ( PhantomData < T > ) ;
8990
91+ #[ derive( Clone ) ]
92+ struct DeferredI64 ;
93+
9094impl < T : BenchPrimitive > RowFn for InfallibleBool < T > {
9195 type Options = EmptyOptions ;
9296
@@ -108,22 +112,69 @@ impl<T: BenchPrimitive> RowFn for InfallibleBool<T> {
108112 }
109113}
110114
115+ impl RowFn for DeferredI64 {
116+ type Options = EmptyOptions ;
117+
118+ const ARG_NAMES : & ' static [ & ' static str ] = & [ "lhs" , "rhs" ] ;
119+ const INFALLIBLE : bool = false ;
120+
121+ fn id ( & self ) -> ScalarFnId {
122+ static ID : CachedId = CachedId :: new ( "bench.row_fn_output.deferred_i64" ) ;
123+ * ID
124+ }
125+
126+ fn dispatch < V : RowVisitor > (
127+ & self ,
128+ _options : & Self :: Options ,
129+ _args : & [ DType ] ,
130+ visitor : V ,
131+ ) -> VortexResult < V :: VisitResult > {
132+ visitor. visit_deferred :: < ( i64 , i64 ) , i64 , bool > (
133+ |( lhs, rhs) | lhs. overflowing_add ( rhs) ,
134+ |overflowed| {
135+ vortex_ensure ! (
136+ !overflowed,
137+ "deferred-i64 benchmark inputs must not overflow"
138+ ) ;
139+ Ok ( ( ) )
140+ } ,
141+ )
142+ }
143+ }
144+
111145#[ vortex_bench_support:: cpu_features]
112146#[ divan:: bench( types = [ i32 , i64 ] , args = INPUT_SHAPES ) ]
113147fn infallible_bool < T : BenchPrimitive > ( bencher : Bencher , & shape: & InputShape ) {
114148 let function = InfallibleBool :: < T > ( PhantomData ) ;
149+ bench_row_fn ( bencher, & function, make_args :: < T > ( shape) ) ;
150+ }
151+
152+ #[ vortex_bench_support:: cpu_features]
153+ #[ divan:: bench( args = INPUT_SHAPES ) ]
154+ fn deferred_i64 ( bencher : Bencher , & shape: & InputShape ) {
155+ bench_row_fn ( bencher, & DeferredI64 , make_args :: < i64 > ( shape) ) ;
156+ }
157+
158+ fn make_args < T : BenchPrimitive > ( shape : InputShape ) -> VecExecutionArgs {
115159 let args = match shape {
116160 InputShape :: PerRowPerRow => vec ! [ T :: per_row( 0 ) , T :: per_row( 1 ) ] ,
117161 InputShape :: PerRowConstant => vec ! [ T :: per_row( 0 ) , T :: constant( ) ] ,
118162 InputShape :: ConstantPerRow => vec ! [ T :: constant( ) , T :: per_row( 1 ) ] ,
119163 } ;
120- let args = VecExecutionArgs :: new ( args, ROWS ) ;
121164
165+ VecExecutionArgs :: new ( args, ROWS )
166+ }
167+
168+ fn bench_row_fn < F : RowFn < Options = EmptyOptions > > (
169+ bencher : Bencher ,
170+ function : & F ,
171+ args : VecExecutionArgs ,
172+ ) {
122173 bencher
123174 . counter ( ItemsCount :: new ( ROWS ) )
124175 . with_inputs ( || ( & args, SESSION . create_execution_ctx ( ) ) )
125176 . bench_refs ( |( args, ctx) | {
126- execute_rows ( & function, & EmptyOptions , * args, ctx)
177+ execute_rows ( function, & EmptyOptions , * args, ctx)
127178 . vortex_expect ( "row execution should succeed in benchmark" )
128179 } ) ;
129180}
0 commit comments