jmh

What can explain the huge performance penalty of writing a reference to a heap location?

跟風遠走 提交于 2019-12-03 06:24:29
While investigating the subtler consequences of generational garbage collectors on application performance, I have hit a quite staggering discrepancy in the performance of a very basic operation – a simple write to a heap location – with respect to whether the value written is primitive or a reference. The microbenchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) @Warmup(iterations = 1, time = 1) @Measurement(iterations = 3, time = 1) @State(Scope.Thread) @Threads(1) @Fork(2) public class Writing { static final int TARGET_SIZE = 1024; static final int[]

Consuming stack traces noticeably slower in Java 11 than Java 8

我们两清 提交于 2019-12-03 01:18:01
问题 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.throwAndConsumeStacktrace avgt 25 21525.584 ± 58.957 ns/op Java version: 9.0.4, vendor: Oracle Corporation Benchmark Mode Cnt Score Error Units MyBenchmark.throwAndConsumeStacktrace avgt 25 28243.899 ± 498.173 ns/op Java version: 10.0.2, vendor: Oracle Corporation Benchmark Mode Cnt Score

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

こ雲淡風輕ζ 提交于 2019-12-02 21:57:31
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 ( yyyy/MM/dd HH:mm:ss ) is fast - about 2 times faster than with the old java date, about 1.5M operations per second on my PC. However, when the pattern contains a time zone ( yyyy/MM/dd HH:mm:ss z ), the performance drops about 15 times with the new java.time API, while with the old API it is about as fast as without a time zone. See the

Consuming stack traces noticeably slower in Java 11 than Java 8

旧城冷巷雨未停 提交于 2019-12-02 16:35:30
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.throwAndConsumeStacktrace avgt 25 21525.584 ± 58.957 ns/op Java version: 9.0.4, vendor: Oracle Corporation Benchmark Mode Cnt Score Error Units MyBenchmark.throwAndConsumeStacktrace avgt 25 28243.899 ± 498.173 ns/op Java version: 10.0.2, vendor: Oracle Corporation Benchmark Mode Cnt Score Error Units MyBenchmark.throwAndConsumeStacktrace avgt 25 28499.736 ± 215.837 ns/op Java version: 11.0

Java 8 stream unpredictable performance drop with no obvious reason

亡梦爱人 提交于 2019-12-02 16:04:45
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 deviations. package benchmark; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import java.io.IOException; import java.util.concurrent.ThreadLocalRandom; import java.util.*; import java.util.function.*; import java.util.stream.*; @Threads(32) @Warmup(iterations = 25) @Measurement(iterations = 5) @State(Scope.Benchmark) @Fork(1)

Strange output when using JMH

心已入冬 提交于 2019-12-01 22:53:44
I'm using jmh to benchmark a simple application (from SO question Unexpected Scalability results in java fork-join ) using maven and following the command-line approach as advised in http://openjdk.java.net/projects/code-tools/jmh/ . After successfully setting up and building the benchmark, I get the following benchmark results using the avgt mode: C:\Users\username\my-app\test>java -jar target/benchmarks.jar -bm avgt -f 1 # JMH 1.10.1 (released 13 days ago) # VM invoker: C:\Program Files\Java\jre1.8.0_45\bin\java.exe # VM options: <none> # Warmup: 20 iterations, 1 s each # Measurement: 20

Minimizing Java function call overhead

北城余情 提交于 2019-12-01 08:21:36
I have a piece of code where it appears, in every test I've run, that function calls have a significant amount of overhead. The code is a tight loop, performing a very simple function on each element of an array (containing 4-8 million int s). Running the code, which consists primarily of for (int y = 1; y < h; ++y) { for (int x = 1; x < w; ++x) { final int p = y * s + x; n[p] = f.apply(d, s, x, y); } } executing something like (final int[] d, final int s, final int x, final int y) -> { final int p = s * y + x; final int a = d[p] * 2 + d[p - 1] + d[p + 1] + d[p - s] + d[p + s]; return (1000 *

Minimizing Java function call overhead

限于喜欢 提交于 2019-12-01 06:20:33
问题 I have a piece of code where it appears, in every test I've run, that function calls have a significant amount of overhead. The code is a tight loop, performing a very simple function on each element of an array (containing 4-8 million int s). Running the code, which consists primarily of for (int y = 1; y < h; ++y) { for (int x = 1; x < w; ++x) { final int p = y * s + x; n[p] = f.apply(d, s, x, y); } } executing something like (final int[] d, final int s, final int x, final int y) -> { final

JMH: Using the same static object in all Benchmark tests

不想你离开。 提交于 2019-12-01 03:36:30
I have a class that constructs some complicated data (imagine a large XML or JSON structure - that sort of thing). Constructing it takes time. So I want to construct it once, and then use that same data in all tests. Currently I basically have a public static object instance defined in a class that defines main , and then refer to it explicitly in the tests (code is a very simplified example): public class Data { // This class constructs some complicated data } public class TestSet { public static final Data PARSE_ME = new Data(...); public static void main(String[] args) throws

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

China☆狼群 提交于 2019-12-01 02:44:01
I'm not able to run simple JMH benchmark inside eclipse. Maven dependencies: <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-core</artifactId> <version>1.12</version> </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-generator-annprocess</artifactId> <version>1.12</version> </dependency> Java code: public class BTest { @Benchmark public void test() { // todo } public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(BTest.class.getSimpleName()) .build(); new Runner(opt).run(); } } Result of run: