@@ -15,11 +15,19 @@ use divan::Bencher;
1515use divan:: counter:: ItemsCount ;
1616use mimalloc:: MiMalloc ;
1717use vortex_array:: ArrayRef ;
18+ use vortex_array:: EmptyMetadata ;
1819use vortex_array:: IntoArray ;
1920use vortex_array:: VortexSessionExecute ;
21+ use vortex_array:: arrays:: ConstantArray ;
2022use vortex_array:: arrays:: FixedSizeListArray ;
2123use vortex_array:: arrays:: MaskedArray ;
2224use vortex_array:: arrays:: PrimitiveArray ;
25+ use vortex_array:: arrays:: scalar_fn:: ScalarFnFactoryExt ;
26+ use vortex_array:: dtype:: DType ;
27+ use vortex_array:: dtype:: Nullability ;
28+ use vortex_array:: dtype:: PType ;
29+ use vortex_array:: scalar:: Scalar ;
30+ use vortex_array:: scalar_fn:: EmptyOptions ;
2331use vortex_array:: validity:: Validity ;
2432use vortex_buffer:: Buffer ;
2533use vortex_tensor:: scalar_fns:: l2_norm:: L2Norm ;
@@ -54,13 +62,25 @@ fn vectors(width: usize) -> ArrayRef {
5462 Vector :: try_new_vector_array ( storage) . unwrap ( )
5563}
5664
65+ fn constant_vector ( width : usize ) -> ArrayRef {
66+ let element_dtype = DType :: Primitive ( PType :: F64 , Nullability :: NonNullable ) ;
67+ let children = ( 0 ..width)
68+ . map ( |i| Scalar :: primitive ( ( ( i % 97 ) as f64 ) - 48.0 , Nullability :: NonNullable ) )
69+ . collect ( ) ;
70+ let storage = Scalar :: fixed_size_list ( element_dtype, children, Nullability :: NonNullable ) ;
71+ let vector = Scalar :: extension :: < Vector > ( EmptyMetadata , storage) ;
72+ ConstantArray :: new ( vector, ELEMENTS / width) . into_array ( )
73+ }
74+
5775fn bench_l2_norm ( bencher : Bencher , input : ArrayRef ) {
5876 let session = vortex_array:: array_session ( ) ;
5977 bencher
6078 . counter ( ItemsCount :: new ( input. len ( ) ) )
6179 . with_inputs ( || {
6280 (
63- L2Norm :: try_new_array ( input. clone ( ) ) . unwrap ( ) . into_array ( ) ,
81+ L2Norm
82+ . try_new_array ( input. len ( ) , EmptyOptions , [ input. clone ( ) ] )
83+ . unwrap ( ) ,
6484 session. create_execution_ctx ( ) ,
6585 )
6686 } )
@@ -80,3 +100,17 @@ fn nullable(bencher: Bencher, width: usize) {
80100 . into_array ( ) ;
81101 bench_l2_norm ( bencher, input) ;
82102}
103+
104+ #[ divan:: bench( args = WIDTHS ) ]
105+ fn constant ( bencher : Bencher , width : usize ) {
106+ bench_l2_norm ( bencher, constant_vector ( width) ) ;
107+ }
108+
109+ #[ divan:: bench( args = WIDTHS ) ]
110+ fn nullable_constant ( bencher : Bencher , width : usize ) {
111+ let validity = Validity :: from_iter ( ( 0 ..ELEMENTS / width) . map ( |i| i % 8 != 0 ) ) ;
112+ let input = MaskedArray :: try_new ( constant_vector ( width) , validity)
113+ . unwrap ( )
114+ . into_array ( ) ;
115+ bench_l2_norm ( bencher, input) ;
116+ }
0 commit comments