|
| 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 tokio::runtime::Runtime; |
| 21 | + |
| 22 | +mod utils; |
| 23 | +use utils::build_catalog; |
| 24 | + |
| 25 | +use iceberg::expr::Reference; |
| 26 | +use iceberg::spec::Datum; |
| 27 | +use iceberg::table::Table; |
| 28 | +use iceberg::Catalog; |
| 29 | + |
| 30 | +async fn setup_async() -> Table { |
| 31 | + let catalog = build_catalog().await; |
| 32 | + let namespaces = catalog.list_namespaces(None).await.unwrap(); |
| 33 | + let table_idents = catalog.list_tables(&namespaces[0]).await.unwrap(); |
| 34 | + catalog.load_table(&table_idents[0]).await.unwrap() |
| 35 | +} |
| 36 | + |
| 37 | +fn setup(runtime: &Runtime) -> Table { |
| 38 | + runtime.block_on(setup_async()) |
| 39 | +} |
| 40 | + |
| 41 | +async fn all_files_all_rows(table: &Table) { |
| 42 | + let scan = table.scan().build().unwrap(); |
| 43 | + let mut stream = scan.plan_files().await.unwrap(); |
| 44 | + |
| 45 | + while let Some(item) = stream.next().await { |
| 46 | + black_box(item.unwrap()); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +async fn one_file_all_rows(table: &Table) { |
| 51 | + let scan = table |
| 52 | + .scan() |
| 53 | + .with_filter( |
| 54 | + Reference::new("tpep_pickup_datetime") |
| 55 | + .greater_than_or_equal_to( |
| 56 | + Datum::timestamptz_from_str("2024-02-01T00:00:00.000 UTC").unwrap(), |
| 57 | + ) |
| 58 | + .and(Reference::new("tpep_pickup_datetime").less_than( |
| 59 | + Datum::timestamptz_from_str("2024-02-02T00:00:00.000 UTC").unwrap(), |
| 60 | + )), |
| 61 | + ) |
| 62 | + .build() |
| 63 | + .unwrap(); |
| 64 | + let mut stream = scan.plan_files().await.unwrap(); |
| 65 | + |
| 66 | + while let Some(item) = stream.next().await { |
| 67 | + black_box(item.unwrap()); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +async fn all_files_some_rows(table: &Table) { |
| 72 | + let scan = table |
| 73 | + .scan() |
| 74 | + .with_filter(Reference::new("passenger_count").equal_to(Datum::double(1.0))) |
| 75 | + .build() |
| 76 | + .unwrap(); |
| 77 | + let mut stream = scan.plan_files().await.unwrap(); |
| 78 | + |
| 79 | + while let Some(item) = stream.next().await { |
| 80 | + black_box(item.unwrap()); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +async fn one_file_some_rows(table: &Table) { |
| 85 | + let scan = table |
| 86 | + .scan() |
| 87 | + .with_filter( |
| 88 | + Reference::new("tpep_pickup_datetime") |
| 89 | + .greater_than_or_equal_to( |
| 90 | + Datum::timestamptz_from_str("2024-02-01T00:00:00.000 UTC").unwrap(), |
| 91 | + ) |
| 92 | + .and(Reference::new("tpep_pickup_datetime").less_than( |
| 93 | + Datum::timestamptz_from_str("2024-02-02T00:00:00.000 UTC").unwrap(), |
| 94 | + )) |
| 95 | + .and(Reference::new("passenger_count").equal_to(Datum::double(1.0))), |
| 96 | + ) |
| 97 | + .build() |
| 98 | + .unwrap(); |
| 99 | + let mut stream = scan.plan_files().await.unwrap(); |
| 100 | + |
| 101 | + while let Some(item) = stream.next().await { |
| 102 | + black_box(item.unwrap()); |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +pub fn bench_all_files_all_rows(c: &mut Criterion) { |
| 107 | + let runtime = Runtime::new().unwrap(); |
| 108 | + let table = setup(&runtime); |
| 109 | + println!("setup complete"); |
| 110 | + |
| 111 | + c.bench_function("all_files_all_rows", |b| { |
| 112 | + b.to_async(&runtime).iter(|| all_files_all_rows(&table)) |
| 113 | + }); |
| 114 | +} |
| 115 | + |
| 116 | +pub fn bench_one_file_all_rows(c: &mut Criterion) { |
| 117 | + let runtime = Runtime::new().unwrap(); |
| 118 | + let table = setup(&runtime); |
| 119 | + println!("setup complete"); |
| 120 | + |
| 121 | + c.bench_function("one_file_all_rows", |b| { |
| 122 | + b.to_async(&runtime).iter(|| one_file_all_rows(&table)) |
| 123 | + }); |
| 124 | +} |
| 125 | + |
| 126 | +pub fn bench_all_files_some_rows(c: &mut Criterion) { |
| 127 | + let runtime = Runtime::new().unwrap(); |
| 128 | + let table = setup(&runtime); |
| 129 | + println!("setup complete"); |
| 130 | + |
| 131 | + c.bench_function("all_files_some_rows", |b| { |
| 132 | + b.to_async(&runtime).iter(|| all_files_some_rows(&table)) |
| 133 | + }); |
| 134 | +} |
| 135 | + |
| 136 | +pub fn bench_one_file_some_rows(c: &mut Criterion) { |
| 137 | + let runtime = Runtime::new().unwrap(); |
| 138 | + let table = setup(&runtime); |
| 139 | + println!("setup complete"); |
| 140 | + |
| 141 | + c.bench_function("one_file_some_rows", |b| { |
| 142 | + b.to_async(&runtime).iter(|| one_file_some_rows(&table)) |
| 143 | + }); |
| 144 | +} |
| 145 | + |
| 146 | +criterion_group! { |
| 147 | + name = benches; |
| 148 | + config = Criterion::default().sample_size(10); |
| 149 | + targets = bench_all_files_all_rows, bench_all_files_some_rows, bench_one_file_all_rows, bench_one_file_some_rows |
| 150 | +} |
| 151 | + |
| 152 | +criterion_main!(benches); |
0 commit comments