From 0b5b6601fae5a4b9580ed0b380bc0b4d42c498f7 Mon Sep 17 00:00:00 2001 From: Vlad Ilyushchenko Date: Fri, 10 May 2019 22:14:05 +0100 Subject: [PATCH] Misc: clock benchmark --- .../main/java/org/questdb/ClockBenchmark.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 benchmarks/src/main/java/org/questdb/ClockBenchmark.java diff --git a/benchmarks/src/main/java/org/questdb/ClockBenchmark.java b/benchmarks/src/main/java/org/questdb/ClockBenchmark.java new file mode 100644 index 000000000..78b27bade --- /dev/null +++ b/benchmarks/src/main/java/org/questdb/ClockBenchmark.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (C) 2014-2019 Appsicle + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + ******************************************************************************/ + +package org.questdb; + +import com.questdb.std.Os; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.concurrent.TimeUnit; + +@State(Scope.Thread) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +public class ClockBenchmark { + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(ClockBenchmark.class.getSimpleName()) + .warmupIterations(5) + .measurementIterations(5) + .addProfiler("gc") + .forks(1) + .build(); + + new Runner(opt).run(); + } + + @Benchmark + public long testCurrentTimeMicros() { + return Os.currentTimeMicros(); + } + + @Benchmark + public long testCurrentTimeNanos() { + return Os.currentTimeNanos(); + } + + @Benchmark + public long testCurrentTimeMillis() { + return System.currentTimeMillis(); + } + +} -- GitLab