Questions tagged [jmh]

The Java Microbenchmark Harness (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.

419 questions
76
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,711
  • 8
  • 52
  • 85
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
  • 84,049
  • 23
  • 157
  • 201
58
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
  • 703
  • 6
  • 8
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,574
  • 18
  • 26
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
  • 86,244
  • 97
  • 390
  • 689
54
votes
10 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
  • 863
  • 1
  • 7
  • 13
48
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
  • 11,657
  • 9
  • 37
  • 57
45
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
  • 195,646
  • 29
  • 319
  • 436
43
votes
4 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
  • 22,436
  • 15
  • 82
  • 99
40
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
  • 117,005
  • 15
  • 201
  • 306
33
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
  • 41,793
  • 59
  • 191
  • 359
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
  • 86,244
  • 97
  • 390
  • 689
32
votes
1 answer

JMH: What does the score value mean?

I don't understand the score attribute from the JMH results? I don't find anything on the web about it, too. Can anyone tell me, what it is about? As far as I understand is a higher score better than a lower, but what does it exactly mean and how is…
markusw
  • 1,975
  • 16
  • 28
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,464
  • 2
  • 18
  • 26
1
2 3
27 28