Last active
February 23, 2017 10:33
-
-
Save vladimirdolzhenko/146493b9ca30489191d62deec63cee4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
$ export TZ=UTC | |
TZ = UTC | |
Benchmark Mode Cnt Score Error Units | |
TZTest.currentTimeMillis avgt 5 40.014 ± 1.383 ns/op | |
TZTest.instant avgt 5 47.798 ± 0.669 ns/op | |
TZTest.nano avgt 5 40.747 ± 1.040 ns/op | |
$ unset TZ | |
TZ = null | |
Benchmark Mode Cnt Score Error Units | |
TZTest.currentTimeMillis avgt 5 39.858 ± 0.116 ns/op | |
TZTest.instant avgt 5 47.785 ± 1.476 ns/op | |
TZTest.nano avgt 5 40.431 ± 0.699 ns/op | |
*/ | |
package com; | |
import java.time.Instant; | |
import java.util.concurrent.TimeUnit; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; | |
import org.openjdk.jmh.annotations.Mode; | |
import org.openjdk.jmh.annotations.OutputTimeUnit; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.State; | |
import org.openjdk.jmh.annotations.Threads; | |
import org.openjdk.jmh.annotations.Warmup; | |
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; | |
/** | |
* @author vladimir.dolzhenko | |
* @since 2017-02-22 | |
*/ | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Fork(1) | |
@Warmup(iterations = 2, time = 5000, timeUnit = TimeUnit.MILLISECONDS) | |
@Measurement(iterations = 5, time = 5000, timeUnit = TimeUnit.MILLISECONDS) | |
@Threads(1) | |
@State(Scope.Benchmark) | |
public class TZTest { | |
@Benchmark | |
public long nano() { | |
return System.nanoTime(); | |
} | |
@Benchmark | |
public long currentTimeMillis() { | |
return System.currentTimeMillis(); | |
} | |
@Benchmark | |
public Instant instant() { | |
return Instant.now(); | |
} | |
public static void main(String[] args) throws RunnerException { | |
System.out.println("TZ = " + System.getenv("TZ")); | |
Options opt = new OptionsBuilder() | |
.include(TZTest.class.getSimpleName()) | |
.build(); | |
new Runner(opt).run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment