From 9265b975152586ebdda5576314133a3c24120f53 Mon Sep 17 00:00:00 2001 From: "Ma, Rong" Date: Thu, 9 May 2024 16:48:20 +0800 Subject: [PATCH] add benchmark --- .../sparksql/benchmarks/CMakeLists.txt | 4 ++ .../sparksql/benchmarks/CompareBenchmark.cpp | 1 + .../sparksql/benchmarks/HashBenchmark.cpp | 53 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 velox/functions/sparksql/benchmarks/HashBenchmark.cpp diff --git a/velox/functions/sparksql/benchmarks/CMakeLists.txt b/velox/functions/sparksql/benchmarks/CMakeLists.txt index 5ccf7e88745af..837c983b7df87 100644 --- a/velox/functions/sparksql/benchmarks/CMakeLists.txt +++ b/velox/functions/sparksql/benchmarks/CMakeLists.txt @@ -27,3 +27,7 @@ target_link_libraries( add_executable(velox_sparksql_benchmarks_compare CompareBenchmark.cpp) target_link_libraries(velox_sparksql_benchmarks_compare velox_functions_spark velox_benchmark_builder velox_vector_test_lib) + +add_executable(velox_sparksql_benchmarks_hash HashBenchmark.cpp) +target_link_libraries(velox_sparksql_benchmarks_hash velox_functions_spark + velox_benchmark_builder velox_vector_test_lib) diff --git a/velox/functions/sparksql/benchmarks/CompareBenchmark.cpp b/velox/functions/sparksql/benchmarks/CompareBenchmark.cpp index 19b6f12625123..e4d3c9f3f6088 100644 --- a/velox/functions/sparksql/benchmarks/CompareBenchmark.cpp +++ b/velox/functions/sparksql/benchmarks/CompareBenchmark.cpp @@ -26,6 +26,7 @@ using namespace facebook::velox; int main(int argc, char** argv) { folly::Init init(&argc, &argv); + memory::MemoryManager::initialize({}); functions::sparksql::registerFunctions(""); ExpressionBenchmarkBuilder benchmarkBuilder; diff --git a/velox/functions/sparksql/benchmarks/HashBenchmark.cpp b/velox/functions/sparksql/benchmarks/HashBenchmark.cpp new file mode 100644 index 0000000000000..97cf592e3b812 --- /dev/null +++ b/velox/functions/sparksql/benchmarks/HashBenchmark.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include +#include + +#include "velox/benchmarks/ExpressionBenchmarkBuilder.h" +#include "velox/functions/sparksql/Register.h" + +using namespace facebook; + +using namespace facebook::velox; + +int main(int argc, char** argv) { + folly::Init init(&argc, &argv); + memory::MemoryManager::initialize({}); + functions::sparksql::registerFunctions(""); + + ExpressionBenchmarkBuilder benchmarkBuilder; + + std::vector inputTypes = { + ARRAY(MAP(INTEGER(), VARCHAR())), + ROW({"f_map", "f_array"}, {MAP(INTEGER(), VARCHAR()), ARRAY(INTEGER())}), + }; + + for (auto& inputType : inputTypes) { + benchmarkBuilder + .addBenchmarkSet( + fmt::format("hash_{}", inputType->toString()), + ROW({"c0"}, {inputType})) + .withFuzzerOptions({.vectorSize = 1000, .nullRatio = 0.1}) + .addExpression("hash", "hash(c0)") + .addExpression("xxhash64", "xxhash64(c0)") + .withIterations(100); + } + + benchmarkBuilder.registerBenchmarks(); + folly::runBenchmarks(); + return 0; +}