@@ -0,0 +1,3223 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.benchmark;%0A%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.BenchmarkMode;%0Aimport org.openjdk.jmh.annotations.Fork;%0Aimport org.openjdk.jmh.annotations.Measurement;%0Aimport org.openjdk.jmh.annotations.Mode;%0Aimport org.openjdk.jmh.annotations.OperationsPerInvocation;%0Aimport org.openjdk.jmh.annotations.OutputTimeUnit;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.annotations.Warmup;%0Aimport org.openjdk.jmh.infra.Blackhole;%0Aimport org.openjdk.jmh.runner.Runner;%0Aimport org.openjdk.jmh.runner.RunnerException;%0Aimport org.openjdk.jmh.runner.options.Options;%0Aimport org.openjdk.jmh.runner.options.OptionsBuilder;%0Aimport org.openjdk.jmh.runner.options.VerboseMode;%0A%0Aimport java.lang.management.ManagementFactory;%0Aimport java.lang.management.ThreadMXBean;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport static java.lang.Integer.getInteger;%0A%0A@State(Scope.Thread)%0A@OutputTimeUnit(TimeUnit.NANOSECONDS)%0A@Fork(2)%0A@Warmup(iterations = 10, time = 2, timeUnit = TimeUnit.SECONDS)%0A@Measurement(iterations = 10, time = 2, timeUnit = TimeUnit.SECONDS)%0A@BenchmarkMode(Mode.AverageTime)%0Apublic class BenchmarkCPUCounters%0A%7B%0A    private static final ThreadMXBean THREAD_MX_BEAN = ManagementFactory.getThreadMXBean();%0A%0A    private static final int ITERATIONS = 1000;%0A%0A    @Benchmark%0A    @OperationsPerInvocation(ITERATIONS)%0A    public void nanoTime(Blackhole blackhole)%0A    %7B%0A        for (int i = 0; i %3C ITERATIONS; i++) %7B%0A            blackhole.consume(System.nanoTime());%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    @OperationsPerInvocation(ITERATIONS)%0A    public void cpuTime(Blackhole blackhole)%0A    %7B%0A        for (int i = 0; i %3C ITERATIONS; i++) %7B%0A            blackhole.consume(currentThreadCpuTime());%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    @OperationsPerInvocation(ITERATIONS)%0A    public void userTime(Blackhole blackhole)%0A    %7B%0A        for (int i = 0; i %3C ITERATIONS; i++) %7B%0A            blackhole.consume(currentThreadUserTime());%0A        %7D%0A    %7D%0A%0A    private static long currentThreadCpuTime()%0A    %7B%0A        return THREAD_MX_BEAN.getCurrentThreadCpuTime();%0A    %7D%0A%0A    private static long currentThreadUserTime()%0A    %7B%0A        return THREAD_MX_BEAN.getCurrentThreadUserTime();%0A    %7D%0A%0A    public static void main(String%5B%5D args)%0A            throws RunnerException%0A    %7B%0A        Options options = new OptionsBuilder()%0A                .verbosity(VerboseMode.NORMAL)%0A                .threads(getInteger(%22threads%22, 1))%0A                .include(%22.*%22 + BenchmarkCPUCounters.class.getSimpleName() + %22.*%22)%0A                .build();%0A%0A        new Runner(options).run();%0A    %7D%0A%7D%0A

Add bechmarks for CPU timers