@@ -24,7 +24,6 @@ use std::sync::Arc;
2424
2525extern crate arrow;
2626
27- use arrow:: compute:: kernels:: limit:: * ;
2827use arrow:: util:: bench_util:: * ;
2928use arrow:: { array:: * , datatypes:: Float32Type } ;
3029use arrow:: { compute:: kernels:: arithmetic:: * , util:: test_util:: seedable_rng} ;
@@ -59,44 +58,69 @@ fn bench_divide(arr_a: &ArrayRef, arr_b: &ArrayRef) {
5958 criterion:: black_box ( divide ( arr_a, arr_b) . unwrap ( ) ) ;
6059}
6160
61+ fn bench_divide_unchecked ( arr_a : & ArrayRef , arr_b : & ArrayRef ) {
62+ let arr_a = arr_a. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
63+ let arr_b = arr_b. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
64+ criterion:: black_box ( divide_unchecked ( arr_a, arr_b) . unwrap ( ) ) ;
65+ }
66+
6267fn bench_divide_scalar ( array : & ArrayRef , divisor : f32 ) {
6368 let array = array. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
6469 criterion:: black_box ( divide_scalar ( array, divisor) . unwrap ( ) ) ;
6570}
6671
67- fn bench_limit ( arr_a : & ArrayRef , max : usize ) {
68- criterion:: black_box ( limit ( arr_a, max) ) ;
72+ fn bench_modulo ( arr_a : & ArrayRef , arr_b : & ArrayRef ) {
73+ let arr_a = arr_a. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
74+ let arr_b = arr_b. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
75+ criterion:: black_box ( modulus ( arr_a, arr_b) . unwrap ( ) ) ;
76+ }
77+
78+ fn bench_modulo_scalar ( array : & ArrayRef , divisor : f32 ) {
79+ let array = array. as_any ( ) . downcast_ref :: < Float32Array > ( ) . unwrap ( ) ;
80+ criterion:: black_box ( modulus_scalar ( array, divisor) . unwrap ( ) ) ;
6981}
7082
7183fn add_benchmark ( c : & mut Criterion ) {
72- let arr_a = create_array ( 512 , false ) ;
73- let arr_b = create_array ( 512 , false ) ;
84+ const BATCH_SIZE : usize = 64 * 1024 ;
85+ let arr_a = create_array ( BATCH_SIZE , false ) ;
86+ let arr_b = create_array ( BATCH_SIZE , false ) ;
7487 let scalar = seedable_rng ( ) . gen ( ) ;
7588
76- c. bench_function ( "add 512" , |b| b. iter ( || bench_add ( & arr_a, & arr_b) ) ) ;
77- c. bench_function ( "subtract 512" , |b| {
78- b. iter ( || bench_subtract ( & arr_a, & arr_b) )
89+ c. bench_function ( "add" , |b| b. iter ( || bench_add ( & arr_a, & arr_b) ) ) ;
90+ c. bench_function ( "subtract" , |b| b. iter ( || bench_subtract ( & arr_a, & arr_b) ) ) ;
91+ c. bench_function ( "multiply" , |b| b. iter ( || bench_multiply ( & arr_a, & arr_b) ) ) ;
92+ c. bench_function ( "divide" , |b| b. iter ( || bench_divide ( & arr_a, & arr_b) ) ) ;
93+ c. bench_function ( "divide_unchecked" , |b| {
94+ b. iter ( || bench_divide_unchecked ( & arr_a, & arr_b) )
7995 } ) ;
80- c. bench_function ( "multiply 512" , |b| {
81- b. iter ( || bench_multiply ( & arr_a, & arr_b) )
82- } ) ;
83- c. bench_function ( "divide 512" , |b| b. iter ( || bench_divide ( & arr_a, & arr_b) ) ) ;
84- c. bench_function ( "divide_scalar 512" , |b| {
96+ c. bench_function ( "divide_scalar" , |b| {
8597 b. iter ( || bench_divide_scalar ( & arr_a, scalar) )
8698 } ) ;
87- c. bench_function ( "limit 512, 512" , |b| b. iter ( || bench_limit ( & arr_a, 512 ) ) ) ;
99+ c. bench_function ( "modulo" , |b| b. iter ( || bench_modulo ( & arr_a, & arr_b) ) ) ;
100+ c. bench_function ( "modulo_scalar" , |b| {
101+ b. iter ( || bench_modulo_scalar ( & arr_a, scalar) )
102+ } ) ;
88103
89- let arr_a_nulls = create_array ( 512 , false ) ;
90- let arr_b_nulls = create_array ( 512 , false ) ;
91- c. bench_function ( "add_nulls_512 " , |b| {
104+ let arr_a_nulls = create_array ( BATCH_SIZE , true ) ;
105+ let arr_b_nulls = create_array ( BATCH_SIZE , true ) ;
106+ c. bench_function ( "add_nulls " , |b| {
92107 b. iter ( || bench_add ( & arr_a_nulls, & arr_b_nulls) )
93108 } ) ;
94- c. bench_function ( "divide_nulls_512 " , |b| {
109+ c. bench_function ( "divide_nulls " , |b| {
95110 b. iter ( || bench_divide ( & arr_a_nulls, & arr_b_nulls) )
96111 } ) ;
97- c. bench_function ( "divide_scalar_nulls_512" , |b| {
112+ c. bench_function ( "divide_nulls_unchecked" , |b| {
113+ b. iter ( || bench_divide_unchecked ( & arr_a_nulls, & arr_b_nulls) )
114+ } ) ;
115+ c. bench_function ( "divide_scalar_nulls" , |b| {
98116 b. iter ( || bench_divide_scalar ( & arr_a_nulls, scalar) )
99117 } ) ;
118+ c. bench_function ( "modulo_nulls" , |b| {
119+ b. iter ( || bench_modulo ( & arr_a_nulls, & arr_b_nulls) )
120+ } ) ;
121+ c. bench_function ( "modulo_scalar_nulls" , |b| {
122+ b. iter ( || bench_modulo_scalar ( & arr_a_nulls, scalar) )
123+ } ) ;
100124}
101125
102126criterion_group ! ( benches, add_benchmark) ;
0 commit comments