Skip to content

Commit

Permalink
update bench
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Oct 24, 2024
1 parent 8472b0a commit 4bc92c8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions parquet/benches/row_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,24 @@ use rand::Rng;
///
/// # Returns
///
/// * A `RowSelection` instance with randomly selected rows based on the provided ratio.
fn generate_random_row_selection(total_rows: usize, selection_ratio: f64) -> RowSelection {
/// * A `BooleanArray` instance with randomly selected rows based on the provided ratio.
fn generate_random_row_selection(total_rows: usize, selection_ratio: f64) -> BooleanArray {
let mut rng = rand::thread_rng();
let bools: Vec<bool> = (0..total_rows)
.map(|_| rng.gen_bool(selection_ratio))
.collect();
let boolean_array = BooleanArray::from(bools);
RowSelection::from_filters(&[boolean_array])
BooleanArray::from(bools)
}

fn criterion_benchmark(c: &mut Criterion) {
let total_rows = 300_000;
let selection_ratio = 1.0 / 3.0;

// Generate two random RowSelections with approximately 1/3 of the rows selected.
let row_selection_a = generate_random_row_selection(total_rows, selection_ratio);
let row_selection_b = generate_random_row_selection(total_rows, selection_ratio);
let row_selection_a =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, selection_ratio)]);
let row_selection_b =
RowSelection::from_filters(&[generate_random_row_selection(total_rows, selection_ratio)]);

// Benchmark the intersection of the two RowSelections.
c.bench_function("intersection", |b| {
Expand All @@ -63,11 +64,7 @@ fn criterion_benchmark(c: &mut Criterion) {
});

c.bench_function("from_filters", |b| {
let mut rng = rand::thread_rng();
let bools: Vec<bool> = (0..total_rows)
.map(|_| rng.gen_bool(selection_ratio))
.collect();
let boolean_array = BooleanArray::from(bools);
let boolean_array = generate_random_row_selection(total_rows, selection_ratio);
b.iter(|| {
let array = boolean_array.clone();
let selection = RowSelection::from_filters(&[array]);
Expand All @@ -77,7 +74,8 @@ fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("and_then", |b| {
let selected = row_selection_a.row_count();
let sub_selection = generate_random_row_selection(selected, selection_ratio);
let sub_selection =
RowSelection::from_filters(&[generate_random_row_selection(selected, selection_ratio)]);
b.iter(|| {
let result = row_selection_a.and_then(&sub_selection);
criterion::black_box(result);
Expand Down

0 comments on commit 4bc92c8

Please sign in to comment.