Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
marin-ma committed Aug 12, 2024
1 parent 95e6716 commit f8f1443
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
10 changes: 7 additions & 3 deletions velox/row/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ velox_add_library(velox_row_fast CompactRow.cpp UnsafeRowFast.cpp)

velox_link_libraries(velox_row_fast PUBLIC velox_vector)

if(${VELOX_BUILD_TESTING})
add_subdirectory(tests)
endif()
if (${VELOX_BUILD_TESTING})
add_subdirectory(tests)
endif ()

if (${VELOX_ENABLE_BENCHMARKS})
add_subdirectory(benchmark)
endif ()
22 changes: 22 additions & 0 deletions velox/row/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_executable(velox_unsafe_row_serialize_benchmark UnsafeRowSerializeBenchmark.cpp)
target_link_libraries(velox_unsafe_row_serialize_benchmark PRIVATE
${FOLLY_BENCHMARK}
velox_common_base
velox_exec
velox_row_fast
velox_vector_fuzzer
Folly::folly)
76 changes: 47 additions & 29 deletions velox/row/benchmark/UnsafeRowSerializeBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,44 @@ class SerializeBenchmark {
VELOX_CHECK_EQ(serialized.size(), data->size());
}

void serializeCompactRange(const RowTypePtr& rowType) {
folly::BenchmarkSuspender suspender;
auto data = makeData(rowType);
suspender.dismiss();

auto numRows = data->size();
std::vector<size_t> offsets(numRows);

CompactRow compact(data);

size_t totalSize = 0;
if (auto fixedRowSize = CompactRow::fixedRowSize(rowType)) {
totalSize = fixedRowSize.value() * numRows;
for (auto i = 0; i < numRows; ++i) {
offsets[i] = fixedRowSize.value() * i;
}
} else {
for (auto i = 0; i < numRows; ++i) {
offsets[i] = totalSize;
totalSize += compact.rowSize(i);
}
}

IndexRange indexRange{0, numRows};
auto buffer = AlignedBuffer::allocate<char>(totalSize, pool(), 0);
auto rawBuffer = buffer->asMutable<char>();
compact.serialize(indexRange, offsets, rawBuffer);
VELOX_CHECK_EQ(offsets.back(), totalSize);

std::vector<std::string_view> serialized;
serialized.push_back(std::string_view(rawBuffer, offsets[0]));
for (auto i = 1; i < numRows; ++i) {
serialized.push_back(std::string_view(
rawBuffer + offsets[i - 1], offsets[i] - offsets[i - 1]));
}
VELOX_CHECK_EQ(serialized.size(), data->size());
}

void deserializeCompact(const RowTypePtr& rowType) {
folly::BenchmarkSuspender suspender;
auto data = makeData(rowType);
Expand Down Expand Up @@ -205,35 +243,15 @@ class SerializeBenchmark {
memory::memoryManager()->addLeafPool()};
};

#define SERDE_BENCHMARKS(name, rowType) \
BENCHMARK(unsafe_serialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.serializeUnsafe(rowType); \
} \
\
BENCHMARK(compact_serialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.serializeCompact(rowType); \
} \
\
BENCHMARK(container_serialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.serializeContainer(rowType); \
} \
\
BENCHMARK(unsafe_deserialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.deserializeUnsafe(rowType); \
} \
\
BENCHMARK(compact_deserialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.deserializeCompact(rowType); \
} \
\
BENCHMARK(container_deserialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.deserializeContainer(rowType); \
#define SERDE_BENCHMARKS(name, rowType) \
BENCHMARK(compact_serialize_##name) { \
SerializeBenchmark benchmark; \
benchmark.serializeCompact(rowType); \
} \
\
BENCHMARK(compact_serialize_range_##name) { \
SerializeBenchmark benchmark; \
benchmark.serializeCompactRange(rowType); \
}

SERDE_BENCHMARKS(
Expand Down

0 comments on commit f8f1443

Please sign in to comment.