]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/parquet/level_conversion_benchmark.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / parquet / level_conversion_benchmark.cc
CommitLineData
1d09f67e
TL
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#include <cstdint>
19#include <vector>
20
21#include "benchmark/benchmark.h"
22#include "parquet/level_conversion.h"
23
24constexpr int64_t kLevelCount = 2048;
25// Def level indicating the element is missing from the leaf
26// array (a parent repeated element was empty).
27constexpr int16_t kMissingDefLevel = 0;
28
29// Definition Level indicating the values has an entry in the leaf element.
30constexpr int16_t kPresentDefLevel = 2;
31
32// A repition level that indicates a repeated element.
33constexpr int16_t kHasRepeatedElements = 1;
34
35std::vector<uint8_t> RunDefinitionLevelsToBitmap(const std::vector<int16_t>& def_levels,
36 ::benchmark::State* state) {
37 std::vector<uint8_t> bitmap(/*count=*/def_levels.size(), 0);
38 parquet::internal::LevelInfo info;
39 info.def_level = kHasRepeatedElements;
40 info.repeated_ancestor_def_level = kPresentDefLevel;
41 info.rep_level = 1;
42 parquet::internal::ValidityBitmapInputOutput validity_io;
43 validity_io.values_read_upper_bound = def_levels.size();
44 validity_io.valid_bits = bitmap.data();
45 for (auto _ : *state) {
46 parquet::internal::DefLevelsToBitmap(def_levels.data(), def_levels.size(), info,
47 &validity_io);
48 }
49 state->SetBytesProcessed(int64_t(state->iterations()) * def_levels.size());
50 return bitmap;
51}
52
53void BM_DefinitionLevelsToBitmapRepeatedAllMissing(::benchmark::State& state) {
54 std::vector<int16_t> def_levels(/*count=*/kLevelCount, kMissingDefLevel);
55 auto result = RunDefinitionLevelsToBitmap(def_levels, &state);
56 ::benchmark::DoNotOptimize(result);
57}
58
59BENCHMARK(BM_DefinitionLevelsToBitmapRepeatedAllMissing);
60
61void BM_DefinitionLevelsToBitmapRepeatedAllPresent(::benchmark::State& state) {
62 std::vector<int16_t> def_levels(/*count=*/kLevelCount, kPresentDefLevel);
63 auto result = RunDefinitionLevelsToBitmap(def_levels, &state);
64 ::benchmark::DoNotOptimize(result);
65}
66
67BENCHMARK(BM_DefinitionLevelsToBitmapRepeatedAllPresent);
68
69void BM_DefinitionLevelsToBitmapRepeatedMostPresent(::benchmark::State& state) {
70 std::vector<int16_t> def_levels(/*count=*/kLevelCount, kPresentDefLevel);
71 for (size_t x = 0; x < def_levels.size(); x++) {
72 if (x % 10 == 0) {
73 def_levels[x] = kMissingDefLevel;
74 }
75 }
76 auto result = RunDefinitionLevelsToBitmap(def_levels, &state);
77 ::benchmark::DoNotOptimize(result);
78}
79
80BENCHMARK(BM_DefinitionLevelsToBitmapRepeatedMostPresent);