richardstartin commented on issue #7866:
URL: https://github.com/apache/pinot/issues/7866#issuecomment-985996820


   In fact there's a simpler problem with the benchmark (once you prevent dead 
code elimination you should see ~2-5ns for `benchmarkThreadCpuTimer`) but you 
need to call `ThreadTimer.setThreadCpuTimeMeasurementEnabled(true)` to actually 
measure anything:
   
   ```java
   @BenchmarkMode(Mode.AverageTime)
   @OutputTimeUnit(TimeUnit.NANOSECONDS)
   @Warmup(iterations = 5, time = 1)
   @Measurement(iterations = 5, time = 1)
   @Fork(1)
   @State(Scope.Benchmark)
   public class BenchmarkTimer {
   
     public static void main(String[] args)
         throws Exception {
       ChainedOptionsBuilder opt = new 
OptionsBuilder().include(BenchmarkTimer.class.getSimpleName());
       new Runner(opt.build()).run();
     }
   
     @Setup(Level.Trial)
     public void setup() {
       ThreadTimer.setThreadCpuTimeMeasurementEnabled(true);
     }
   
     @Benchmark
     public long benchmarkThreadCpuTimer() {
       ThreadTimer threadTimer = new ThreadTimer();
       return threadTimer.getThreadTimeNs();
     }
   
     @Benchmark
     public long benchmarkSystemCurrentTimeMillis() {
       long startWallClockTimeMs = System.currentTimeMillis();
       long totalWallClockTimeMs = System.currentTimeMillis() - 
startWallClockTimeMs;
       return TimeUnit.MILLISECONDS.toNanos(totalWallClockTimeMs);
     }
   
     @Benchmark
     public long benchmarkSystemNanoTime() {
       long startWallClockTimeNs = System.nanoTime();
       return System.nanoTime() - startWallClockTimeNs;
     }
   }
   ```
   
   I ran this on my MacBook Pro
   ```
   Benchmark                                        Mode  Cnt     Score     
Error  Units
   BenchmarkTimer.benchmarkSystemCurrentTimeMillis  avgt    5    52.619 ±   
4.729  ns/op
   BenchmarkTimer.benchmarkSystemNanoTime           avgt    5    61.667 ±   
6.172  ns/op
   BenchmarkTimer.benchmarkThreadCpuTimer           avgt    5  2504.818 ± 
181.180  ns/op
   ```
   
   Again, if you want to see this really blow up, run it on Xen.


-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to