jmh

Erratic performance of Arrays.stream().map().sum()

牧云@^-^@ 提交于 2019-12-07 03:06:27
问题 I have chanced upon an instance of exceedingly erratic performance profile of a very simple map/reduce operation on primitive arrays. Here is my jmh benchmark code: @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @OperationsPerInvocation(Measure.ARRAY_SIZE) @Warmup(iterations = 300, time = 200, timeUnit=MILLISECONDS) @Measurement(iterations = 1, time = 1000, timeUnit=MILLISECONDS) @State(Scope.Thread) @Threads(1) @Fork(1) public class Measure { static final int ARRAY

shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer

别来无恙 提交于 2019-12-06 22:11:52
问题 I'm working on a maven project. I'm trying to integrate jmh benchmarking into my project. The pom.xml of my maven project... <parent> <groupId>platform</groupId> <artifactId>platform-root</artifactId> <version>3.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> <artifactId>platform-migration</artifactId> <packaging>jar</packaging> <name>Platform Migration</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compile.source>1.7<

Simple micro-benchmark with JMH

久未见 提交于 2019-12-06 08:04:50
问题 Inspired by another question on Stack Overflow, I have written a micro-benchmark to check, what is more efficient: conditionally checking for zero divisor or catching and handling an ArithmeticException Below is my code: @State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class MyBenchmark { private int a = 10; // a little bit less obvious than int b = 0; private int b = (int) Math.floor(Math.random()); @Benchmark public float conditional() { if

What exactly is number of operations in JMH?

别说谁变了你拦得住时间么 提交于 2019-12-05 23:54:18
问题 The JavaDoc of annotation @OperationsPerInvocation in the Java Microbenchmarking Harness (JMH) states: value public abstract int value Returns: Number of operations per single Benchmark call. Default: 1 Being new to JMH I am wondering what type of operation (byte code operation, assembly code operation, Java operation etc) is meant here. This question naturally refers to all places in JMH (documentation, output, comments etc) where the term 'operation' is used (e.g. " operation/time " unit or

How can I use JMH for Scala benchmarks together with sbt?

六月ゝ 毕业季﹏ 提交于 2019-12-05 16:07:37
问题 I have tried to use jmh together with sbt, but so far I have not managed to set it up properly so that .scala based benchmarks work. As the combination sbt + .java based benchmarks works, I tried to start from that base. I am using sbt 0.13.1. .java based benchmarks using sbt build.sbt import AssemblyKeys._ name := "scala-benchmark" version := "1.0" scalaVersion := "2.10.3" scalacOptions += "-deprecation" libraryDependencies += "org.openjdk.jmh" % "jmh-core" % "0.5.5" libraryDependencies +=

Do java caches results of the methods

自古美人都是妖i 提交于 2019-12-05 10:41:40
I use JMH to specify the complexity of the operation. If you've never worked with JMH, don't worry. JMH will just launch the estimateOperation method multiple times and then get the average time. Question: [narrow] will this program calculate Math.cbrt(Integer.MAX_VALUE) each time? Or it just calculate it once and return cached result afterwards? @GenerateMicroBenchmark public void estimateOperation() { calculate(); } public int calculate() { return Math.cbrt(Integer.MAX_VALUE); } Question: [broad]: Does JVM ever cache the result of the methods? The method return value is never cached .

Count metrics with JMH

旧时模样 提交于 2019-12-05 07:51:48
How can I use to calculate the amount of CPU time and memory in JMH? For example, I have: Code: @State(Scope.Thread) @BenchmarkMode(Mode.All) public class JMHSample_My { int x = 1; int y = 2; @GenerateMicroBenchmark public int measureAdd() { return (x + y); } @GenerateMicroBenchmark public int measureMul() { return (x * y); } public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(".*" + JMHSample_My.class.getSimpleName() + ".*") .warmupIterations(5) .measurementIterations(5) .forks(1) .build(); new Runner(opt).run(); } } Result: Benchmark

Erratic performance of Arrays.stream().map().sum()

╄→гoц情女王★ 提交于 2019-12-05 07:21:39
I have chanced upon an instance of exceedingly erratic performance profile of a very simple map/reduce operation on primitive arrays. Here is my jmh benchmark code: @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @OperationsPerInvocation(Measure.ARRAY_SIZE) @Warmup(iterations = 300, time = 200, timeUnit=MILLISECONDS) @Measurement(iterations = 1, time = 1000, timeUnit=MILLISECONDS) @State(Scope.Thread) @Threads(1) @Fork(1) public class Measure { static final int ARRAY_SIZE = 1<<20; final int[] ds = new int[ARRAY_SIZE]; private IntUnaryOperator mapper; @Setup public void

shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer

馋奶兔 提交于 2019-12-05 01:59:11
I'm working on a maven project. I'm trying to integrate jmh benchmarking into my project. The pom.xml of my maven project... <parent> <groupId>platform</groupId> <artifactId>platform-root</artifactId> <version>3.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> <artifactId>platform-migration</artifactId> <packaging>jar</packaging> <name>Platform Migration</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compile.source>1.7</maven.compile.source> <maven.compile.target>1.7</maven.compile.target> <jmh.version>1.1.1</jmh.version>

System.arraycopy with constant length

不羁岁月 提交于 2019-12-04 23:28:23
I'm playing around with JMH ( http://openjdk.java.net/projects/code-tools/jmh/ ) and I just stumbled on a strange result. I'm benchmarking ways to make a shallow copy of an array and I can observe the expected results (that looping through the array is a bad idea and that there is no significant difference between #clone() , System#arraycopy() and Arrays#copyOf() , performance-wise). Except that System#arraycopy() is one-quarter slower when the array's length is hard-coded... Wait, what ? How can this be slower ? Does anyone has an idea of what could be the cause ? The results (throughput): #