|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +use criterion::*; |
| 19 | +use futures_util::StreamExt; |
| 20 | +use iceberg::expr::Reference; |
| 21 | +use iceberg::spec::Datum; |
| 22 | +use iceberg::table::Table; |
| 23 | +use tokio::runtime::Runtime; |
| 24 | +mod utils; |
| 25 | +use utils::setup; |
| 26 | + |
| 27 | +async fn all_files_all_rows(table: &Table) { |
| 28 | + let scan = table.scan().build().unwrap(); |
| 29 | + let mut stream = scan.plan_files().await.unwrap(); |
| 30 | + |
| 31 | + while let Some(item) = stream.next().await { |
| 32 | + black_box(item.unwrap()); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +async fn one_file_all_rows(table: &Table) { |
| 37 | + let scan = table |
| 38 | + .scan() |
| 39 | + .with_filter( |
| 40 | + Reference::new("tpep_pickup_datetime") |
| 41 | + .greater_than_or_equal_to( |
| 42 | + Datum::timestamptz_from_str("2024-02-01T00:00:00.000 UTC").unwrap(), |
| 43 | + ) |
| 44 | + .and(Reference::new("tpep_pickup_datetime").less_than( |
| 45 | + Datum::timestamptz_from_str("2024-02-02T00:00:00.000 UTC").unwrap(), |
| 46 | + )), |
| 47 | + ) |
| 48 | + .build() |
| 49 | + .unwrap(); |
| 50 | + let mut stream = scan.plan_files().await.unwrap(); |
| 51 | + |
| 52 | + while let Some(item) = stream.next().await { |
| 53 | + black_box(item.unwrap()); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +async fn all_files_some_rows(table: &Table) { |
| 58 | + let scan = table |
| 59 | + .scan() |
| 60 | + .with_filter(Reference::new("passenger_count").equal_to(Datum::double(1.0))) |
| 61 | + .build() |
| 62 | + .unwrap(); |
| 63 | + let mut stream = scan.plan_files().await.unwrap(); |
| 64 | + |
| 65 | + while let Some(item) = stream.next().await { |
| 66 | + black_box(item.unwrap()); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +async fn one_file_some_rows(table: &Table) { |
| 71 | + let scan = |
| 72 | + table |
| 73 | + .scan() |
| 74 | + .with_filter( |
| 75 | + Reference::new("tpep_pickup_datetime") |
| 76 | + .greater_than_or_equal_to( |
| 77 | + Datum::timestamptz_from_str("2024-02-01T00:00:00.000 UTC").unwrap(), |
| 78 | + ) |
| 79 | + .and(Reference::new("tpep_pickup_datetime").less_than( |
| 80 | + Datum::timestamptz_from_str("2024-02-02T00:00:00.000 UTC").unwrap(), |
| 81 | + )) |
| 82 | + .and(Reference::new("passenger_count").equal_to(Datum::double(1.0))), |
| 83 | + ) |
| 84 | + .build() |
| 85 | + .unwrap(); |
| 86 | + let mut stream = scan.plan_files().await.unwrap(); |
| 87 | + |
| 88 | + while let Some(item) = stream.next().await { |
| 89 | + black_box(item.unwrap()); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +pub fn bench_all_files_all_rows(c: &mut Criterion) { |
| 94 | + let runtime = Runtime::new().unwrap(); |
| 95 | + let table = setup(&runtime); |
| 96 | + println!("setup complete"); |
| 97 | + |
| 98 | + c.bench_function("scan: plan (all files, all rows)", |b| { |
| 99 | + b.to_async(&runtime).iter(|| all_files_all_rows(&table)) |
| 100 | + }); |
| 101 | +} |
| 102 | + |
| 103 | +pub fn bench_one_file_all_rows(c: &mut Criterion) { |
| 104 | + let runtime = Runtime::new().unwrap(); |
| 105 | + let table = setup(&runtime); |
| 106 | + println!("setup complete"); |
| 107 | + |
| 108 | + c.bench_function("scan: plan (one file, all rows)", |b| { |
| 109 | + b.to_async(&runtime).iter(|| one_file_all_rows(&table)) |
| 110 | + }); |
| 111 | +} |
| 112 | + |
| 113 | +pub fn bench_all_files_some_rows(c: &mut Criterion) { |
| 114 | + let runtime = Runtime::new().unwrap(); |
| 115 | + let table = setup(&runtime); |
| 116 | + println!("setup complete"); |
| 117 | + |
| 118 | + c.bench_function("scan: plan (all files, some rows)", |b| { |
| 119 | + b.to_async(&runtime).iter(|| all_files_some_rows(&table)) |
| 120 | + }); |
| 121 | +} |
| 122 | + |
| 123 | +pub fn bench_one_file_some_rows(c: &mut Criterion) { |
| 124 | + let runtime = Runtime::new().unwrap(); |
| 125 | + let table = setup(&runtime); |
| 126 | + println!("setup complete"); |
| 127 | + |
| 128 | + c.bench_function("scan: plan (one file, some rows)", |b| { |
| 129 | + b.to_async(&runtime).iter(|| one_file_some_rows(&table)) |
| 130 | + }); |
| 131 | +} |
| 132 | + |
| 133 | +criterion_group! { |
| 134 | + name = benches; |
| 135 | + config = Criterion::default().sample_size(10); |
| 136 | + targets = bench_all_files_all_rows, bench_all_files_some_rows, bench_one_file_all_rows, bench_one_file_some_rows |
| 137 | +} |
| 138 | + |
| 139 | +criterion_main!(benches); |
0 commit comments