From ab69ce06275a55afa1a2c462b4f8c2a66a8adf7f Mon Sep 17 00:00:00 2001 From: Karteek Date: Fri, 13 Sep 2024 09:43:30 -0700 Subject: [PATCH] Add benchmark tests for CAST INTEGER/BIGINT to DECIMAL (#9568) Summary: This PR adds `CAST INTEGER/BITINT to SHORT/LONG DECIMAL` benchmarking test. ``` ============================================================================ [...]hmarks/ExpressionBenchmarkBuilder.cpp relative time/iter iters/s ============================================================================ cast##try_cast_invalid_empty_input 888.87us 1.13K cast##tryexpr_cast_invalid_empty_input 366.60ms 2.73 cast##try_cast_invalid_nan 482.08ms 2.07 cast##tryexpr_cast_invalid_nan 834.13ms 1.20 cast##try_cast_valid 4.52ms 221.42 cast##tryexpr_cast_valid 4.52ms 221.16 cast##cast_valid 4.52ms 221.42 cast##cast_decimal_to_inline_string 2.21ms 451.69 cast##cast_short_decimal 3.14ms 318.79 cast##cast_long_decimal 5.05ms 197.88 cast##cast_large_real_to_scientific_notation 10.45ms 95.74 cast##cast_small_real_to_standard_notation 5.77ms 173.40 cast##cast_small_double_to_scientific_notation 12.60ms 79.39 cast##cast_large_double_to_standard_notation 7.34ms 136.21 cast##cast_timestamp 3.94ms 253.68 cast##cast_real_as_int 404.66us 2.47K cast##cast_decimal_as_bigint 969.12us 1.03K cast##cast_int_as_short_decimal 911.29us 1.10K cast##cast_int_as_long_decimal 925.29us 1.08K cast##cast_bigint_as_short_decimal 906.91us 1.10K cast##cast_bigint_as_long_decimal 922.87us 1.08K ``` The positive relative time implies Velox is slower compared to DuckDb: Here is how the relative time computed: ``` trialResults[actualTrials] = std::make_pair( max(0.0, double(nsecs.count()) / timeIterData.niter - globalBaseline), std::move(timeIterData.userCounters)); ``` Pull Request resolved: https://github.com/facebookincubator/velox/pull/9568 Reviewed By: Yuhta Differential Revision: D62599114 Pulled By: kevinwilfong fbshipit-source-id: 1bad04fd2418d2daa84cb45564ae9dd7f68e5818 --- velox/benchmarks/basic/CastBenchmark.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/velox/benchmarks/basic/CastBenchmark.cpp b/velox/benchmarks/basic/CastBenchmark.cpp index 14aba0d34c36..f937f354f893 100644 --- a/velox/benchmarks/basic/CastBenchmark.cpp +++ b/velox/benchmarks/basic/CastBenchmark.cpp @@ -48,6 +48,14 @@ int main(int argc, char** argv) { vectorSize, [](auto /*row*/) { return "infinity"; }); auto spaceInput = vectorMaker.flatVector( vectorSize, [](auto /*row*/) { return " "; }); + auto integerInput = vectorMaker.flatVector( + vectorSize, [&](auto j) { return 12345 * j; }, nullptr); + auto bigintInput = vectorMaker.flatVector( + vectorSize, + [&](auto j) { + return facebook::velox::HugeInt::build(12345 * j, 56789 * j + 12345); + }, + nullptr); auto decimalInput = vectorMaker.flatVector( vectorSize, [&](auto j) { return 12345 * j; }, nullptr, DECIMAL(9, 2)); auto shortDecimalInput = vectorMaker.flatVector( @@ -148,6 +156,8 @@ int main(int argc, char** argv) { {"valid", "empty", "invalid", + "integer", + "bigint", "decimal", "short_decimal", "long_decimal", @@ -158,6 +168,8 @@ int main(int argc, char** argv) { {validInput, emptyInput, invalidInput, + integerInput, + bigintInput, decimalInput, shortDecimalInput, longDecimalInput, @@ -191,6 +203,14 @@ int main(int argc, char** argv) { "cast(large_double as varchar)") .addExpression("cast_real_as_int", "cast (small_real as integer)") .addExpression("cast_decimal_as_bigint", "cast (short_decimal as bigint)") + .addExpression( + "cast_int_as_short_decimal", "cast (integer as decimal(18,6))") + .addExpression( + "cast_int_as_long_decimal", "cast (integer as decimal(38,16))") + .addExpression( + "cast_bigint_as_short_decimal", "cast (bigint as decimal(18,6))") + .addExpression( + "cast_bigint_as_long_decimal", "cast (bigint as decimal(38,16))") .withIterations(100) .disableTesting();