@@ -32,80 +32,140 @@ extern crate arrow;
3232use arrow:: util:: bench_util:: create_primitive_array;
3333use arrow:: util:: test_util:: seedable_rng;
3434
35+ const ARRAY_LEN : usize = 8_192 ;
36+
37+ // These bitwise kernels are very cheap, so run them many times per Criterion iteration to
38+ // try and reduce noise in the benchmarks.
39+ const RUNS_PER_SAMPLE : usize = 100 ;
40+
3541fn bitwise_array_benchmark ( c : & mut Criterion ) {
36- let size = 64 * 1024_usize ;
37- let left_without_null = create_primitive_array :: < Int64Type > ( size, 0 as f32 ) ;
38- let right_without_null = create_primitive_array :: < Int64Type > ( size, 0 as f32 ) ;
39- let left_with_null = create_primitive_array :: < Int64Type > ( size, 0.2_f32 ) ;
40- let right_with_null = create_primitive_array :: < Int64Type > ( size, 0.2_f32 ) ;
42+ let left_without_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0 as f32 ) ;
43+ let right_without_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0 as f32 ) ;
44+ let left_with_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0.2_f32 ) ;
45+ let right_with_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0.2_f32 ) ;
4146 // array and
4247 let mut group = c. benchmark_group ( "bench bitwise array: and" ) ;
4348 group. bench_function ( "bitwise array and, no nulls" , |b| {
44- b. iter ( || hint:: black_box ( bitwise_and ( & left_without_null, & right_without_null) . unwrap ( ) ) )
49+ b. iter ( || {
50+ for _ in 0 ..RUNS_PER_SAMPLE {
51+ hint:: black_box ( bitwise_and ( & left_without_null, & right_without_null) . unwrap ( ) ) ;
52+ }
53+ } )
4554 } ) ;
4655 group. bench_function ( "bitwise array and, 20% nulls" , |b| {
47- b. iter ( || hint:: black_box ( bitwise_and ( & left_with_null, & right_with_null) . unwrap ( ) ) )
56+ b. iter ( || {
57+ for _ in 0 ..RUNS_PER_SAMPLE {
58+ hint:: black_box ( bitwise_and ( & left_with_null, & right_with_null) . unwrap ( ) ) ;
59+ }
60+ } )
4861 } ) ;
4962 group. finish ( ) ;
5063 // array or
5164 let mut group = c. benchmark_group ( "bench bitwise: or" ) ;
5265 group. bench_function ( "bitwise array or, no nulls" , |b| {
53- b. iter ( || hint:: black_box ( bitwise_or ( & left_without_null, & right_without_null) . unwrap ( ) ) )
66+ b. iter ( || {
67+ for _ in 0 ..RUNS_PER_SAMPLE {
68+ hint:: black_box ( bitwise_or ( & left_without_null, & right_without_null) . unwrap ( ) ) ;
69+ }
70+ } )
5471 } ) ;
5572 group. bench_function ( "bitwise array or, 20% nulls" , |b| {
56- b. iter ( || hint:: black_box ( bitwise_or ( & left_with_null, & right_with_null) . unwrap ( ) ) )
73+ b. iter ( || {
74+ for _ in 0 ..RUNS_PER_SAMPLE {
75+ hint:: black_box ( bitwise_or ( & left_with_null, & right_with_null) . unwrap ( ) ) ;
76+ }
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+ for _ in 0 ..RUNS_PER_SAMPLE {
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+ for _ in 0 ..RUNS_PER_SAMPLE {
92+ hint:: black_box ( bitwise_xor ( & left_with_null, & right_with_null) . unwrap ( ) ) ;
93+ }
94+ } )
6695 } ) ;
6796 group. finish ( ) ;
6897 // not
6998 let mut group = c. benchmark_group ( "bench bitwise: not" ) ;
7099 group. bench_function ( "bitwise array not, no nulls" , |b| {
71- b. iter ( || hint:: black_box ( bitwise_not ( & left_without_null) . unwrap ( ) ) )
100+ b. iter ( || {
101+ for _ in 0 ..RUNS_PER_SAMPLE {
102+ hint:: black_box ( bitwise_not ( & left_without_null) . unwrap ( ) ) ;
103+ }
104+ } ) ;
72105 } ) ;
73106 group. bench_function ( "bitwise array not, 20% nulls" , |b| {
74- b. iter ( || hint:: black_box ( bitwise_not ( & left_with_null) . unwrap ( ) ) )
107+ b. iter ( || {
108+ for _ in 0 ..RUNS_PER_SAMPLE {
109+ hint:: black_box ( bitwise_not ( & left_with_null) . unwrap ( ) ) ;
110+ }
111+ } ) ;
75112 } ) ;
76113 group. finish ( ) ;
77114}
78115
79116fn bitwise_array_scalar_benchmark ( c : & mut Criterion ) {
80- let size = 64 * 1024_usize ;
81- let array_without_null = create_primitive_array :: < Int64Type > ( size, 0 as f32 ) ;
82- let array_with_null = create_primitive_array :: < Int64Type > ( size, 0.2_f32 ) ;
117+ let array_without_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0 as f32 ) ;
118+ let array_with_null = create_primitive_array :: < Int64Type > ( ARRAY_LEN , 0.2_f32 ) ;
83119 let scalar = seedable_rng ( ) . next_u64 ( ) as i64 ;
84120 // array scalar and
85121 let mut group = c. benchmark_group ( "bench bitwise array scalar: and" ) ;
86122 group. bench_function ( "bitwise array scalar and, no nulls" , |b| {
87- b. iter ( || hint:: black_box ( bitwise_and_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
123+ b. iter ( || {
124+ for _ in 0 ..RUNS_PER_SAMPLE {
125+ hint:: black_box ( bitwise_and_scalar ( & array_without_null, scalar) . unwrap ( ) ) ;
126+ }
127+ } )
88128 } ) ;
89129 group. bench_function ( "bitwise array and, 20% nulls" , |b| {
90- b. iter ( || hint:: black_box ( bitwise_and_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
130+ b. iter ( || {
131+ for _ in 0 ..RUNS_PER_SAMPLE {
132+ hint:: black_box ( bitwise_and_scalar ( & array_with_null, scalar) . unwrap ( ) ) ;
133+ }
134+ } )
91135 } ) ;
92136 group. finish ( ) ;
93137 // array scalar or
94138 let mut group = c. benchmark_group ( "bench bitwise array scalar: or" ) ;
95139 group. bench_function ( "bitwise array scalar or, no nulls" , |b| {
96- b. iter ( || hint:: black_box ( bitwise_or_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
140+ b. iter ( || {
141+ for _ in 0 ..RUNS_PER_SAMPLE {
142+ hint:: black_box ( bitwise_or_scalar ( & array_without_null, scalar) . unwrap ( ) ) ;
143+ }
144+ } )
97145 } ) ;
98146 group. bench_function ( "bitwise array scalar or, 20% nulls" , |b| {
99- b. iter ( || hint:: black_box ( bitwise_or_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
147+ b. iter ( || {
148+ for _ in 0 ..RUNS_PER_SAMPLE {
149+ hint:: black_box ( bitwise_or_scalar ( & array_with_null, scalar) . unwrap ( ) ) ;
150+ }
151+ } )
100152 } ) ;
101153 group. finish ( ) ;
102154 // array scalar xor
103155 let mut group = c. benchmark_group ( "bench bitwise array scalar: xor" ) ;
104156 group. bench_function ( "bitwise array scalar xor, no nulls" , |b| {
105- b. iter ( || hint:: black_box ( bitwise_xor_scalar ( & array_without_null, scalar) . unwrap ( ) ) )
157+ b. iter ( || {
158+ for _ in 0 ..RUNS_PER_SAMPLE {
159+ hint:: black_box ( bitwise_xor_scalar ( & array_without_null, scalar) . unwrap ( ) ) ;
160+ }
161+ } )
106162 } ) ;
107163 group. bench_function ( "bitwise array scalar xor, 20% nulls" , |b| {
108- b. iter ( || hint:: black_box ( bitwise_xor_scalar ( & array_with_null, scalar) . unwrap ( ) ) )
164+ b. iter ( || {
165+ for _ in 0 ..RUNS_PER_SAMPLE {
166+ hint:: black_box ( bitwise_xor_scalar ( & array_with_null, scalar) . unwrap ( ) ) ;
167+ }
168+ } )
109169 } ) ;
110170 group. finish ( ) ;
111171}
0 commit comments