Questions tagged [jmh]

The jmh is a Java harness for building, running, and analysing nano/micro/macro benchmarks written in Java and other languages targetting the JVM.

jmh is a Java harness for building, running, and analysing nano/micro/macro benchmarks written in Java and other languages targetting the JVM. It is part of openjdk.

355 questions
76
votes
2 answers

Why is StringBuilder#append(int) faster in Java 7 than in Java 8?

While investigating for a little debate w.r.t. using "" + n and Integer.toString(int) to convert an integer primitive to a string I wrote this JMH microbenchmark: @Fork(1) @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Benchmark) public class…
thkala
  • 76,870
  • 21
  • 145
  • 185
75
votes
2 answers

Why is returning a Java object reference so much slower than returning a primitive

We are working on a latency sensitive application and have been microbenchmarking all kinds of methods (using jmh). After microbenchmarking a lookup method and being satisfied with the results, I implemented the final version, only to find that the…
Sam Goldberg
  • 6,474
  • 7
  • 43
  • 79
56
votes
1 answer

Mystifying microbenchmark result for stream API on Java 12 vs. Java 8 with -gc true

As part of my investigation on the difference between using a complex filter or multiple filters in streams, I notice that performance on Java 12 is way slower than on Java 8. Is any explanation for those weird results? Did I miss something here?…
Serge
  • 2,094
  • 15
  • 26
55
votes
1 answer

Java 8 stream unpredictable performance drop with no obvious reason

I am using Java 8 streams to iterate over a list with sublists. The outer list size varies between 100 to 1000 (different test runs) and the inner list size is always 5. There are 2 benchmark runs which show unexpected performance…
alexd84
  • 673
  • 6
  • 8
54
votes
0 answers

Java 11 -- performance regressions against Java 8?

UPDATE: Seeing as each method might be suffering from a different performance issue I decided to split this question into two: Empty methods noticeably slower in Java 11 than Java 8 Consuming stack traces noticeably slower in Java 11 than Java…
Gili
  • 76,473
  • 85
  • 341
  • 624
46
votes
1 answer

Why is the StringBuilder chaining pattern sb.append(x).append(y) faster than regular sb.append(x); sb.append(y)?

I have a microbenchmark that shows very strange results: @BenchmarkMode(Mode.Throughput) @Fork(1) @State(Scope.Thread) @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS, batchSize = 1000) @Measurement(iterations = 40, time = 1, timeUnit…
Dmitriy Dumanskiy
  • 8,478
  • 8
  • 27
  • 51
44
votes
1 answer

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

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…
Marko Topolnik
  • 179,046
  • 25
  • 276
  • 399
39
votes
4 answers

Why is zipped faster than zip in Scala?

I have written some Scala code to perform an element-wise operation on a collection. Here I defined two methods that perform the same task. One method uses zip and the other uses zipped. def ES (arr :Array[Double], arr1 :Array[Double])…
39
votes
2 answers

newInstance vs new in jdk-9/jdk-8 and jmh

I've seen a lot of threads here that compare and try to answer which is faster: newInstance or new operator. Looking at the source code, it would seem that newInstance should be much slower, I mean it does so many security checks and uses…
Eugene
  • 102,901
  • 10
  • 149
  • 252
38
votes
2 answers

How to run JMH from inside JUnit tests?

How can I run JMH benchmarks inside my existing project using JUnit tests? The official documentation recommends making a separate project, using Maven shade plugin, and launching JMH inside the main method. Is this necessary and why is it…
Aleksandr Dubinsky
  • 19,357
  • 14
  • 64
  • 88
34
votes
5 answers

JMH Unable to find the resource: /META-INF/BenchmarkList

I'm not able to run simple JMH benchmark inside eclipse. Maven dependencies: org.openjdk.jmh jmh-core 1.12
riva
  • 635
  • 1
  • 5
  • 13
32
votes
1 answer

Empty methods noticeably slower in Java 11 than Java 8

I was comparing the performance of JDK 8 and 11 using jmh 1.21 when I ran across some surprising numbers: Java version: 1.8.0_192, vendor: Oracle Corporation Benchmark Mode Cnt Score Error Units MyBenchmark.emptyMethod avgt …
Gili
  • 76,473
  • 85
  • 341
  • 624
31
votes
2 answers

Extremely slow parsing of time zone with the new java.time API

I was just migrating a module from the old java dates to the new java.time API, and noticed a huge drop in performance. It boiled down to parsing of dates with timezone (I parse millions of them at a time). Parsing of date string without a time zone…
Jan X Marek
  • 2,264
  • 16
  • 26
28
votes
2 answers

Consuming stack traces noticeably slower in Java 11 than Java 8

I was comparing the performance of JDK 8 and 11 using jmh 1.21 when I ran across some surprising numbers: Java version: 1.8.0_192, vendor: Oracle Corporation Benchmark Mode Cnt Score Error …
Gili
  • 76,473
  • 85
  • 341
  • 624
25
votes
3 answers

What is the purpose of JMH @Fork?

If IIUC each fork creates a separate virtual machine for the reason that each virtual machine instance might run with slight differences in JIT instructions? I'm also curious about what the time attribute does in the below…
Ole
  • 29,797
  • 32
  • 110
  • 232
1
2 3
23 24