MCPcopy Create free account
hub / github.com/apache/arrow / UnaryBitBlockBenchmark

Class UnaryBitBlockBenchmark

cpp/src/arrow/util/bit_block_counter_benchmark.cc:34–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace internal {
33
34struct UnaryBitBlockBenchmark {
35 benchmark::State& state;
36 int64_t offset;
37 int64_t bitmap_length;
38 std::shared_ptr<Array> arr;
39 int64_t expected;
40
41 explicit UnaryBitBlockBenchmark(benchmark::State& state, int64_t offset = 0)
42 : state(state), offset(offset), bitmap_length(1 << 20) {
43 random::RandomArrayGenerator rng(/*seed=*/0);
44 // State parameter is the average number of total values for each null
45 // value. So 100 means that 1 out of 100 on average are null.
46 double null_probability = 1. / static_cast<double>(state.range(0));
47 arr = rng.Int8(bitmap_length, 0, 100, null_probability);
48
49 // Compute the expected result
50 this->expected = 0;
51 const auto& int8_arr = static_cast<const Int8Array&>(*arr);
52 for (int64_t i = this->offset; i < bitmap_length; ++i) {
53 if (int8_arr.IsValid(i)) {
54 this->expected += int8_arr.Value(i);
55 }
56 }
57 }
58
59 template <typename NextBlockFunc>
60 void BenchBitBlockCounter(NextBlockFunc&& next_block) {
61 const auto& int8_arr = static_cast<const Int8Array&>(*arr);
62 const uint8_t* bitmap = arr->null_bitmap_data();
63 for (auto _ : state) {
64 BitBlockCounter scanner(bitmap, this->offset, bitmap_length - this->offset);
65 int64_t result = 0;
66 int64_t position = this->offset;
67 while (true) {
68 BitBlockCount block = next_block(&scanner);
69 if (block.length == 0) {
70 break;
71 }
72 if (block.length == block.popcount) {
73 // All not-null
74 for (int64_t i = 0; i < block.length; ++i) {
75 result += int8_arr.Value(position + i);
76 }
77 } else if (block.popcount > 0) {
78 // Some but not all not-null
79 for (int64_t i = 0; i < block.length; ++i) {
80 if (bit_util::GetBit(bitmap, position + i)) {
81 result += int8_arr.Value(position + i);
82 }
83 }
84 }
85 position += block.length;
86 }
87 // Sanity check
88 if (result != expected) {
89 std::abort();
90 }
91 }

Callers 6

BitBlockCounterSumFunction · 0.85
BitmapReaderSumFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected