Skip to content

Commit

Permalink
Add benchmark tests for CAST INTEGER/BIGINT to DECIMAL (facebookincub…
Browse files Browse the repository at this point in the history
…ator#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: facebookincubator#9568

Reviewed By: Yuhta

Differential Revision: D62599114

Pulled By: kevinwilfong

fbshipit-source-id: 1bad04fd2418d2daa84cb45564ae9dd7f68e5818
  • Loading branch information
karteekmurthys authored and facebook-github-bot committed Sep 13, 2024
1 parent 580c356 commit ab69ce0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions velox/benchmarks/basic/CastBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ int main(int argc, char** argv) {
vectorSize, [](auto /*row*/) { return "infinity"; });
auto spaceInput = vectorMaker.flatVector<std::string>(
vectorSize, [](auto /*row*/) { return " "; });
auto integerInput = vectorMaker.flatVector<int32_t>(
vectorSize, [&](auto j) { return 12345 * j; }, nullptr);
auto bigintInput = vectorMaker.flatVector<int64_t>(
vectorSize,
[&](auto j) {
return facebook::velox::HugeInt::build(12345 * j, 56789 * j + 12345);
},
nullptr);
auto decimalInput = vectorMaker.flatVector<int64_t>(
vectorSize, [&](auto j) { return 12345 * j; }, nullptr, DECIMAL(9, 2));
auto shortDecimalInput = vectorMaker.flatVector<int64_t>(
Expand Down Expand Up @@ -148,6 +156,8 @@ int main(int argc, char** argv) {
{"valid",
"empty",
"invalid",
"integer",
"bigint",
"decimal",
"short_decimal",
"long_decimal",
Expand All @@ -158,6 +168,8 @@ int main(int argc, char** argv) {
{validInput,
emptyInput,
invalidInput,
integerInput,
bigintInput,
decimalInput,
shortDecimalInput,
longDecimalInput,
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ab69ce0

Please sign in to comment.