|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | +#include "benchmark/benchmark.h" |
| 16 | +#include "absl/log/check.h" |
| 17 | +#include "arolla/qtype/base_types.h" |
| 18 | +#include "koladata/internal/data_bag.h" |
| 19 | +#include "koladata/internal/data_item.h" |
| 20 | +#include "koladata/internal/data_slice.h" |
| 21 | +#include "koladata/internal/op_utils/deep_op_benchmarks_util.h" |
| 22 | +#include "koladata/internal/op_utils/deep_clone.h" |
| 23 | + |
| 24 | +namespace koladata::internal { |
| 25 | +namespace { |
| 26 | + |
| 27 | +using benchmarks_utils::RunBenchmarksFn; |
| 28 | + |
| 29 | +void RunBenchmarks(benchmark::State& state, DataSliceImpl& ds, DataItem& schema, |
| 30 | + DataBagImplPtr& databag, |
| 31 | + DataBagImpl::FallbackSpan fallbacks) { |
| 32 | + while (state.KeepRunning()) { |
| 33 | + benchmark::DoNotOptimize(ds); |
| 34 | + benchmark::DoNotOptimize(schema); |
| 35 | + benchmark::DoNotOptimize(databag); |
| 36 | + benchmark::DoNotOptimize(fallbacks); |
| 37 | + auto result_db = DataBagImpl::CreateEmptyDatabag(); |
| 38 | + DeepCloneOp(result_db.get())(ds, schema, *databag, fallbacks).IgnoreError(); |
| 39 | + benchmark::DoNotOptimize(result_db); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +void BM_DisjointChains(benchmark::State& state) { |
| 44 | + benchmarks_utils::BM_DisjointChains(state, RunBenchmarks); |
| 45 | +} |
| 46 | +BENCHMARK(BM_DisjointChains)->Apply(benchmarks_utils::kBenchmarkFn); |
| 47 | + |
| 48 | +void BM_DisjointChainsObjects(benchmark::State& state) { |
| 49 | + benchmarks_utils::BM_DisjointChainsObjects(state, RunBenchmarks); |
| 50 | +} |
| 51 | +BENCHMARK(BM_DisjointChainsObjects)->Apply(benchmarks_utils::kBenchmarkFn); |
| 52 | + |
| 53 | +void BM_DAG(benchmark::State& state) { |
| 54 | + benchmarks_utils::BM_DAG(state, RunBenchmarks); |
| 55 | +} |
| 56 | +BENCHMARK(BM_DAG)->Apply(benchmarks_utils::kLayersBenchmarkFn); |
| 57 | + |
| 58 | +void BM_DAGObjects(benchmark::State& state) { |
| 59 | + benchmarks_utils::BM_DAGObjects(state, RunBenchmarks); |
| 60 | +} |
| 61 | +BENCHMARK(BM_DAGObjects)->Apply(benchmarks_utils::kLayersBenchmarkFn); |
| 62 | + |
| 63 | +} // namespace |
| 64 | +} // namespace koladata::internal |
0 commit comments