You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mapleFU (via GitHub)" <gi...@apache.org> on 2023/05/09 17:11:50 UTC
[GitHub] [arrow] mapleFU commented on pull request #35422: MINOR: [C++] Use [] instead of exception-throwing at(i) in concatenate.cc
mapleFU commented on PR #35422:
URL: https://github.com/apache/arrow/pull/35422#issuecomment-1540558340
```c++
static void VectorIndex(benchmark::State& state) {
// Code inside this loop is measured repeatedly
std::vector<int64_t> range_vec(10000, 0);
for (auto _ : state) {
// Make sure the variable is not optimized away by compiler
for (int i = 0; i < 10000; ++i) {
int64_t v = range_vec[i];
benchmark::DoNotOptimize(v);
}
}
}
// Register the function as a benchmark
BENCHMARK(VectorIndex);
static void VectorAt(benchmark::State& state) {
// Code inside this loop is measured repeatedly
std::vector<int64_t> range_vec(10000, 0);
for (auto _ : state) {
// Make sure the variable is not optimized away by compiler
for (int i = 0; i < 10000; ++i) {
int64_t v = range_vec.at(i);
benchmark::DoNotOptimize(v);
}
}
}
BENCHMARK(VectorAt);
```
With release(-O2) on my MacOS:
```
------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------
VectorIndex 24632 ns 17785 ns 38620
VectorAt 37438 ns 31141 ns 21829
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org