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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to