@@ -32,6 +32,15 @@ extern crate arrow;
3232use arrow:: util:: bench_util:: create_primitive_array;
3333use arrow:: util:: test_util:: seedable_rng;
3434
35+ // These bitwise kernels are very cheap, so run them many times per Criterion iteration
36+ const RUNS_PER_SAMPLE : usize = 1_000 ;
37+
38+ fn repeat_runs < T > ( mut f : impl FnMut ( ) -> T ) {
39+ for _ in 0 ..RUNS_PER_SAMPLE {
40+ f ( ) ;
41+ }
42+ }
43+
3544fn bitwise_array_benchmark ( c : & mut Criterion ) {
3645 let size = 64 * 1024_usize ;
3746 let left_without_null = create_primitive_array :: < Int64Type > ( size, 0 as f32 ) ;
@@ -41,37 +50,55 @@ fn bitwise_array_benchmark(c: &mut Criterion) {
4150 // array and
4251 let mut group = c. benchmark_group ( "bench bitwise array: and" ) ;
4352 group. bench_function ( "bitwise array and, no nulls" , |b| {
44- b. iter ( || hint:: black_box ( bitwise_and ( & left_without_null, & right_without_null) . unwrap ( ) ) )
53+ b. iter ( || {
54+ repeat_runs ( || {
55+ hint:: black_box ( bitwise_and ( & left_without_null, & right_without_null) . unwrap ( ) )
56+ } )
57+ } )
4558 } ) ;
4659 group. bench_function ( "bitwise array and, 20% nulls" , |b| {
47- b. iter ( || hint:: black_box ( bitwise_and ( & left_with_null, & right_with_null) . unwrap ( ) ) )
60+ b. iter ( || {
61+ repeat_runs ( || hint:: black_box ( bitwise_and ( & left_with_null, & right_with_null) . unwrap ( ) ) )
62+ } )
4863 } ) ;
4964 group. finish ( ) ;
5065 // array or
5166 let mut group = c. benchmark_group ( "bench bitwise: or" ) ;
5267 group. bench_function ( "bitwise array or, no nulls" , |b| {
53- b. iter ( || hint:: black_box ( bitwise_or ( & left_without_null, & right_without_null) . unwrap ( ) ) )
68+ b. iter ( || {
69+ repeat_runs ( || {
70+ hint:: black_box ( bitwise_or ( & left_without_null, & right_without_null) . unwrap ( ) )
71+ } )
72+ } )
5473 } ) ;
5574 group. bench_function ( "bitwise array or, 20% nulls" , |b| {
56- b. iter ( || hint:: black_box ( bitwise_or ( & left_with_null, & right_with_null) . unwrap ( ) ) )
75+ b. iter ( || {
76+ repeat_runs ( || hint:: black_box ( bitwise_or ( & left_with_null, & right_with_null) . unwrap ( ) ) )
77+ } )
5778 } ) ;
5879 group. finish ( ) ;
5980 // xor
6081 let mut group = c. benchmark_group ( "bench bitwise: xor" ) ;
6182 group. bench_function ( "bitwise array xor, no nulls" , |b| {
62- b. iter ( || hint:: black_box ( bitwise_xor ( & left_without_null, & right_without_null) . unwrap ( ) ) )
83+ b. iter ( || {
84+ repeat_runs ( || {
85+ hint:: black_box ( bitwise_xor ( & left_without_null, & right_without_null) . unwrap ( ) )
86+ } )
87+ } )
6388 } ) ;
6489 group. bench_function ( "bitwise array xor, 20% nulls" , |b| {
65- b. iter ( || hint:: black_box ( bitwise_xor ( & left_with_null, & right_with_null) . unwrap ( ) ) )
90+ b. iter ( || {
91+ repeat_runs ( || hint:: black_box ( bitwise_xor ( & left_with_null, & right_with_null) . unwrap ( ) ) )
92+ } )
6693 } ) ;
6794 group. finish ( ) ;
6895 // not
6996 let mut group = c. benchmark_group ( "bench bitwise: not" ) ;
7097 group. bench_function ( "bitwise array not, no nulls" , |b| {
71- b. iter ( || hint:: black_box ( bitwise_not ( & left_without_null) . unwrap ( ) ) )
98+ b. iter ( || repeat_runs ( || hint:: black_box ( bitwise_not ( & left_without_null) . unwrap ( ) ) ) )
7299 } ) ;
73100 group. bench_function ( "bitwise array not, 20% nulls" , |b| {
74- b. iter ( || hint:: black_box ( bitwise_not ( & left_with_null) . unwrap ( ) ) )
101+ b. iter ( || repeat_runs ( || hint:: black_box ( bitwise_not ( & left_with_null) . unwrap ( ) ) ) )
75102 } ) ;
76103 group. finish ( ) ;
77104}
@@ -84,28 +111,44 @@ fn bitwise_array_scalar_benchmark(c: &mut Criterion) {
84111 // array scalar and
85112 let mut group = c. benchmark_group ( "bench bitwise array scalar: and" ) ;
86113 group. bench_function ( "bitwise array scalar and, no nulls" , |b| {
87- b. iter ( || hint:: black_box ( bitwise_and_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
114+ b. iter ( || {
115+ repeat_runs ( || {
116+ hint:: black_box ( bitwise_and_scalar ( & array_without_null, scalar) . unwrap ( ) )
117+ } )
118+ } )
88119 } ) ;
89120 group. bench_function ( "bitwise array and, 20% nulls" , |b| {
90- b. iter ( || hint:: black_box ( bitwise_and_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
121+ b. iter ( || {
122+ repeat_runs ( || hint:: black_box ( bitwise_and_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
123+ } )
91124 } ) ;
92125 group. finish ( ) ;
93126 // array scalar or
94127 let mut group = c. benchmark_group ( "bench bitwise array scalar: or" ) ;
95128 group. bench_function ( "bitwise array scalar or, no nulls" , |b| {
96- b. iter ( || hint:: black_box ( bitwise_or_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
129+ b. iter ( || {
130+ repeat_runs ( || hint:: black_box ( bitwise_or_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
131+ } )
97132 } ) ;
98133 group. bench_function ( "bitwise array scalar or, 20% nulls" , |b| {
99- b. iter ( || hint:: black_box ( bitwise_or_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
134+ b. iter ( || {
135+ repeat_runs ( || hint:: black_box ( bitwise_or_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
136+ } )
100137 } ) ;
101138 group. finish ( ) ;
102139 // array scalar xor
103140 let mut group = c. benchmark_group ( "bench bitwise array scalar: xor" ) ;
104141 group. bench_function ( "bitwise array scalar xor, no nulls" , |b| {
105- b. iter ( || hint:: black_box ( bitwise_xor_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
142+ b. iter ( || {
143+ repeat_runs ( || {
144+ hint:: black_box ( bitwise_xor_scalar ( & array_without_null, scalar) . unwrap ( ) )
145+ } )
146+ } )
106147 } ) ;
107148 group. bench_function ( "bitwise array scalar xor, 20% nulls" , |b| {
108- b. iter ( || hint:: black_box ( bitwise_xor_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
149+ b. iter ( || {
150+ repeat_runs ( || hint:: black_box ( bitwise_xor_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
151+ } )
109152 } ) ;
110153 group. finish ( ) ;
111154}
0 commit comments