What does OpenJDK JMH “score error” exactly mean?

This is the margin of error for the score. In most cases, that is a half of confidence interval. Think about it as if there is a “±” sign between “Score” and “Score error”. In fact, the human-readable log will show that: Result: 1.986 ±(99.9%) 0.009 ops/ns [Average] Statistics: (min, avg, max) = (1.984, 1.986, … Read more

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

As noted in your question and in my comment, ZoneRulesProvider.getAvailableZoneIds() creates a new set of all the available time zones’ string representation (the keys of the static final ConcurrentMap<String, ZoneRulesProvider> ZONES) each time a time zone needs to be parsed.1 Fortunately, a ZoneRulesProvider is an abstract class which is designed to be subclassed. The method … Read more

Empty methods noticeably slower in Java 11 than Java 8

You are measuring empty benchmarks, not empty methods. In other words, measuring the minimal infrastructure code that handles the benchmark itself. This is easy to dissect, because you’d expect only a few instructions on the hot path. JMH’s -prof perfasm or -prof xperfasm would give you those hottest instructions in seconds. I think the effect … Read more

JMH: What does the score value mean?

JMH supports the following Benchmark modes: Throughput: operations per unit of time AverageTime: average time per operation SampleTime: samples the time for each operation SingleShotTime: measures the time for a single operation Now you can analyse if higher score is better or not. The default benchmark mode is (Throughput) 1 and in this case higher … Read more

What is the purpose of JMH @Fork?

JMH offers the fork functionality for a few reasons. One is compilation profile separation as discussed by Rafael above. But this behaviour is not controlled by the @Forks annotation (unless you choose 0 forks, which means no subprocesses are forked to run benchmarks at all). You can choose to run all the benchmarks as part … Read more

Why is zipped faster than zip in Scala?

None of the other answers mention the primary reason for the difference in speed, which is that the zipped version avoids 10,000 tuple allocations. As a couple of the other answers do note, the zip version involves an intermediate array, while the zipped version doesn’t, but allocating an array for 10,000 elements isn’t what makes … Read more

How to run JMH from inside JUnit tests?

I’ve been running JMH inside my existing Maven project using JUnit with no apparent ill effects. I cannot answer why the authors recommend doing things differently. I have not observed a difference in results. JMH launches a separate JVM to run benchmarks to isolate them. Here is what I do: Add the JMH dependencies to … Read more

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

String concatenation a + b + c is a very frequent pattern in Java programs, so HotSpot JVM has a special optimization for it: -XX:+OptimizeStringConcat which is ON by default. HotSpot JVM recognizes new StringBuilder().append()…append().toString() pattern in the bytecode and translates it to the optimized machine code without calling actual Java methods and without allocating … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)