You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/07/08 18:38:33 UTC
[arrow] branch master updated: ARROW-5777: [C++] Add microbenchmark
for some Decimal128 operations
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 6b99b64 ARROW-5777: [C++] Add microbenchmark for some Decimal128 operations
6b99b64 is described below
commit 6b99b64334e408af9f2dd9928eaea19118b1d81c
Author: Micah Kornfield <em...@gmail.com>
AuthorDate: Mon Jul 8 13:38:16 2019 -0500
ARROW-5777: [C++] Add microbenchmark for some Decimal128 operations
After updating the benchmark to be more realistic it doesn't look like there are any gains to be had.
Author: Micah Kornfield <em...@gmail.com>
Closes #4739 from emkornfield/decimal_benchmark and squashes the following commits:
8598d900d <Micah Kornfield> remove ;
aabd35a95 <Micah Kornfield> use auto _ : state
---
cpp/src/arrow/util/decimal-benchmark.cc | 118 +++++++++++++++++++++++++-------
1 file changed, 94 insertions(+), 24 deletions(-)
diff --git a/cpp/src/arrow/util/decimal-benchmark.cc b/cpp/src/arrow/util/decimal-benchmark.cc
index 41cb861..620593c 100644
--- a/cpp/src/arrow/util/decimal-benchmark.cc
+++ b/cpp/src/arrow/util/decimal-benchmark.cc
@@ -34,7 +34,7 @@ static void FromString(benchmark::State& state) { // NOLINT non-const reference
"123456789.123456789",
"1231234567890.451234567890"};
- while (state.KeepRunning()) {
+ for (auto _ : state) {
for (const auto& value : values) {
Decimal128 dec;
int32_t scale, precision;
@@ -44,57 +44,127 @@ static void FromString(benchmark::State& state) { // NOLINT non-const reference
state.SetItemsProcessed(state.iterations() * values.size());
}
+constexpr int32_t kValueSize = 10;
+
static void BinaryCompareOp(benchmark::State& state) { // NOLINT non-const reference
- BasicDecimal128 d1(546, 123), d2(123, 456);
- while (state.KeepRunning()) {
- benchmark::DoNotOptimize(d1 == d2);
- benchmark::DoNotOptimize(d1 <= d2);
- benchmark::DoNotOptimize(d1 >= d2);
- benchmark::DoNotOptimize(d1 >= d1);
+ std::vector<BasicDecimal128> v1, v2;
+ for (int x = 0; x < kValueSize; x++) {
+ v1.emplace_back(100 + x, 100 + x);
+ v2.emplace_back(200 + x, 200 + x);
+ }
+ for (auto _ : state) {
+ for (int x = 0; x < kValueSize; x += 4) {
+ benchmark::DoNotOptimize(v1[x] == v2[x]);
+ benchmark::DoNotOptimize(v1[x + 1] <= v2[x + 1]);
+ benchmark::DoNotOptimize(v1[x + 2] >= v2[x + 2]);
+ benchmark::DoNotOptimize(v1[x + 3] >= v1[x + 3]);
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * kValueSize);
+}
+
+static void BinaryCompareOpConstant(
+ benchmark::State& state) { // NOLINT non-const reference
+ std::vector<BasicDecimal128> v1;
+ for (int x = 0; x < kValueSize; x++) {
+ v1.emplace_back(100 + x, 100 + x);
+ }
+ BasicDecimal128 constant(313, 212);
+ for (auto _ : state) {
+ for (int x = 0; x < kValueSize; x += 4) {
+ benchmark::DoNotOptimize(v1[x] == constant);
+ benchmark::DoNotOptimize(v1[x + 1] <= constant);
+ benchmark::DoNotOptimize(v1[x + 2] >= constant);
+ benchmark::DoNotOptimize(v1[x + 3] != constant);
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * kValueSize);
+}
+
+static void BinaryMathOpAggregate(
+ benchmark::State& state) { // NOLINT non-const reference
+ std::vector<BasicDecimal128> v;
+ for (int x = 0; x < kValueSize; x++) {
+ v.emplace_back(100 + x, 100 + x);
+ }
+
+ for (auto _ : state) {
+ BasicDecimal128 result;
+ for (int x = 0; x < 100; x++) {
+ result += v[x];
+ }
+ benchmark::DoNotOptimize(result);
}
+ state.SetItemsProcessed(state.iterations() * kValueSize);
}
static void BinaryMathOp(benchmark::State& state) { // NOLINT non-const reference
- BasicDecimal128 d1(546, 123), d2(123, 456), d3(0, 10);
- while (state.KeepRunning()) {
- benchmark::DoNotOptimize(d1 - d2);
- benchmark::DoNotOptimize(d1 + d2);
- benchmark::DoNotOptimize(d1 * d2);
- benchmark::DoNotOptimize(d1 / d2);
- benchmark::DoNotOptimize(d1 % d3);
+ std::vector<BasicDecimal128> v1, v2;
+ for (int x = 0; x < kValueSize; x++) {
+ v1.emplace_back(100 + x, 100 + x);
+ v2.emplace_back(200 + x, 200 + x);
+ }
+
+ for (auto _ : state) {
+ for (int x = 0; x < kValueSize; x += 5) {
+ benchmark::DoNotOptimize(v1[x] - v2[x]);
+ benchmark::DoNotOptimize(v1[x + 1] + v2[x + 1]);
+ benchmark::DoNotOptimize(v1[x + 2] * v2[x + 2]);
+ benchmark::DoNotOptimize(v1[x + 3] / v2[x + 3]);
+ benchmark::DoNotOptimize(v1[x + 4] % v2[x + 4]);
+ }
}
+ state.SetItemsProcessed(state.iterations() * kValueSize);
}
static void UnaryOp(benchmark::State& state) { // NOLINT non-const reference
- BasicDecimal128 d1(-546, 123), d2(-123, 456);
- while (state.KeepRunning()) {
- benchmark::DoNotOptimize(d1.Abs());
- benchmark::DoNotOptimize(d2.Negate());
+ std::vector<BasicDecimal128> v;
+ for (int x = 0; x < kValueSize; x++) {
+ v.emplace_back(100 + x, 100 + x);
}
+
+ for (auto _ : state) {
+ for (int x = 0; x < kValueSize; x += 2) {
+ benchmark::DoNotOptimize(v[x].Abs());
+ benchmark::DoNotOptimize(v[x + 1].Negate());
+ }
+ }
+ state.SetItemsProcessed(state.iterations() * kValueSize);
}
static void Constants(benchmark::State& state) { // NOLINT non-const reference
BasicDecimal128 d1(-546, 123), d2(-123, 456);
- while (state.KeepRunning()) {
+ for (auto _ : state) {
benchmark::DoNotOptimize(BasicDecimal128::GetMaxValue() - d1);
benchmark::DoNotOptimize(BasicDecimal128::GetScaleMultiplier(3) + d2);
}
+ state.SetItemsProcessed(state.iterations() * 2);
}
static void BinaryBitOp(benchmark::State& state) { // NOLINT non-const reference
- BasicDecimal128 d1(546, 123), d2(123, 456);
- while (state.KeepRunning()) {
- benchmark::DoNotOptimize(d1 |= d2);
- benchmark::DoNotOptimize(d1 &= d2);
+ std::vector<BasicDecimal128> v1, v2;
+ for (int x = 0; x < kValueSize; x++) {
+ v1.emplace_back(100 + x, 100 + x);
+ v2.emplace_back(200 + x, 200 + x);
+ }
+
+ for (auto _ : state) {
+ for (int x = 0; x < kValueSize; x += 2) {
+ benchmark::DoNotOptimize(v1[x] |= v2[x]);
+ benchmark::DoNotOptimize(v1[x + 1] &= v2[x + 1]);
+ }
}
+ state.SetItemsProcessed(state.iterations() * kValueSize);
}
BENCHMARK(FromString);
BENCHMARK(BinaryMathOp);
+BENCHMARK(BinaryMathOpAggregate);
BENCHMARK(BinaryCompareOp);
-BENCHMARK(BinaryBitOp);
+BENCHMARK(BinaryCompareOpConstant);
BENCHMARK(UnaryOp);
BENCHMARK(Constants);
+BENCHMARK(BinaryBitOp);
} // namespace Decimal
} // namespace arrow