17
17
18
18
use arrow_array:: BooleanArray ;
19
19
use criterion:: * ;
20
- use parquet:: arrow:: arrow_reader:: RowSelection ;
20
+ use parquet:: arrow:: arrow_reader:: { BooleanRowSelection , RowSelection } ;
21
21
use rand:: Rng ;
22
22
23
23
/// Generates a random RowSelection with a specified selection ratio.
@@ -40,47 +40,86 @@ fn generate_random_row_selection(total_rows: usize, selection_ratio: f64) -> Boo
40
40
41
41
fn criterion_benchmark ( c : & mut Criterion ) {
42
42
let total_rows = 300_000 ;
43
- let selection_ratio = 1.0 / 3.0 ;
43
+ let selection_ratios = [ 0.000_01 , 0.001 , 0.1 , 0.3 ] ;
44
44
45
- // Generate two random RowSelections with approximately 1/3 of the rows selected.
46
- let row_selection_a =
47
- RowSelection :: from_filters ( & [ generate_random_row_selection ( total_rows, selection_ratio ) ] ) ;
48
- let row_selection_b =
49
- RowSelection :: from_filters ( & [ generate_random_row_selection ( total_rows, selection_ratio ) ] ) ;
45
+ for ratio in selection_ratios {
46
+ let slice_selection_a =
47
+ RowSelection :: from_filters ( & [ generate_random_row_selection ( total_rows, ratio ) ] ) ;
48
+ let slice_selection_b =
49
+ RowSelection :: from_filters ( & [ generate_random_row_selection ( total_rows, ratio ) ] ) ;
50
50
51
- // Benchmark the intersection of the two RowSelections.
52
- c. bench_function ( "intersection" , |b| {
53
- b. iter ( || {
54
- let intersection = row_selection_a. intersection ( & row_selection_b) ;
55
- criterion:: black_box ( intersection) ;
56
- } )
57
- } ) ;
51
+ let boolean_selection_a = BooleanRowSelection :: from ( slice_selection_a. clone ( ) ) ;
52
+ let boolean_selection_b = BooleanRowSelection :: from ( slice_selection_b. clone ( ) ) ;
58
53
59
- c. bench_function ( "union" , |b| {
60
- b. iter ( || {
61
- let union = row_selection_a. union ( & row_selection_b) ;
62
- criterion:: black_box ( union) ;
63
- } )
64
- } ) ;
54
+ // Benchmark the intersection of the two RowSelections.
55
+ c. bench_function ( & format ! ( "slice intersection {}" , ratio) , |b| {
56
+ b. iter ( || {
57
+ let intersection = slice_selection_a. intersection ( & slice_selection_b) ;
58
+ criterion:: black_box ( intersection) ;
59
+ } )
60
+ } ) ;
65
61
66
- c. bench_function ( "from_filters" , |b| {
67
- let boolean_array = generate_random_row_selection ( total_rows, selection_ratio) ;
68
- b. iter ( || {
69
- let array = boolean_array. clone ( ) ;
70
- let selection = RowSelection :: from_filters ( & [ array] ) ;
71
- criterion:: black_box ( selection) ;
72
- } )
73
- } ) ;
62
+ c. bench_function ( & format ! ( "boolean intersection {}" , ratio) , |b| {
63
+ b. iter ( || {
64
+ let intersection = boolean_selection_a. intersection ( & boolean_selection_b) ;
65
+ criterion:: black_box ( intersection) ;
66
+ } )
67
+ } ) ;
74
68
75
- c. bench_function ( "and_then" , |b| {
76
- let selected = row_selection_a. row_count ( ) ;
77
- let sub_selection =
78
- RowSelection :: from_filters ( & [ generate_random_row_selection ( selected, selection_ratio) ] ) ;
79
- b. iter ( || {
80
- let result = row_selection_a. and_then ( & sub_selection) ;
81
- criterion:: black_box ( result) ;
82
- } )
83
- } ) ;
69
+ c. bench_function ( & format ! ( "slice union {}" , ratio) , |b| {
70
+ b. iter ( || {
71
+ let union = slice_selection_a. union ( & slice_selection_b) ;
72
+ criterion:: black_box ( union) ;
73
+ } )
74
+ } ) ;
75
+
76
+ c. bench_function ( & format ! ( "boolean union {}" , ratio) , |b| {
77
+ b. iter ( || {
78
+ let union = boolean_selection_a. union ( & boolean_selection_b) ;
79
+ criterion:: black_box ( union) ;
80
+ } )
81
+ } ) ;
82
+
83
+ c. bench_function ( & format ! ( "slice from_filters {}" , ratio) , |b| {
84
+ let boolean_array = generate_random_row_selection ( total_rows, ratio) ;
85
+ b. iter ( || {
86
+ let array = boolean_array. clone ( ) ;
87
+ let selection = RowSelection :: from_filters ( & [ array] ) ;
88
+ criterion:: black_box ( selection) ;
89
+ } )
90
+ } ) ;
91
+
92
+ c. bench_function ( & format ! ( "boolean from_filters {}" , ratio) , |b| {
93
+ let boolean_array = generate_random_row_selection ( total_rows, ratio) ;
94
+ b. iter ( || {
95
+ let array = boolean_array. clone ( ) ;
96
+ let selection = BooleanRowSelection :: from_filters ( & [ array] ) ;
97
+ criterion:: black_box ( selection) ;
98
+ } )
99
+ } ) ;
100
+
101
+ c. bench_function ( & format ! ( "slice and_then {}" , ratio) , |b| {
102
+ let selected = slice_selection_a. row_count ( ) ;
103
+ let sub_selection =
104
+ RowSelection :: from_filters ( & [ generate_random_row_selection ( selected, ratio) ] ) ;
105
+ b. iter ( || {
106
+ let result = slice_selection_a. and_then ( & sub_selection) ;
107
+ criterion:: black_box ( result) ;
108
+ } )
109
+ } ) ;
110
+
111
+ c. bench_function ( & format ! ( "boolean and_then {}" , ratio) , |b| {
112
+ let selected = boolean_selection_a. row_count ( ) ;
113
+ let sub_selection =
114
+ BooleanRowSelection :: from_filters ( & [ generate_random_row_selection (
115
+ selected, ratio,
116
+ ) ] ) ;
117
+ b. iter ( || {
118
+ let result = boolean_selection_a. and_then ( & sub_selection) ;
119
+ criterion:: black_box ( result) ;
120
+ } )
121
+ } ) ;
122
+ }
84
123
}
85
124
86
125
criterion_group ! ( benches, criterion_benchmark) ;
0 commit comments