jmh

Is it possible to make java.lang.invoke.MethodHandle as fast as direct invokation?

大兔子大兔子 提交于 2020-01-01 04:56:07
问题 I'm comparing performance of MethodHandle::invoke and direct static method invokation. Here is the static method: public class IntSum { public static int sum(int a, int b){ return a + b; } } And here is my benchmark: @State(Scope.Benchmark) public class MyBenchmark { public int first; public int second; public final MethodHandle mhh; @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) public int directMethodCall() { return IntSum.sum(first, second); } @Benchmark

Strange output when using JMH

旧街凉风 提交于 2019-12-31 02:56:45
问题 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

JMH doesn't run inside a Java Module (Unable to find the resource: /META-INF/BenchmarkList)

烂漫一生 提交于 2019-12-24 10:18:15
问题 I took a project that uses maven-surefire-plugin (automated tests) to trigger JMH benchmarks and added module-info.java to it. Now, META-INF/BenchmarkList is no longer getting generated (in fact, the entire directory is missing) so I end up with the following error when launching the benchmarks: ERROR: Unable to find the resource: /META-INF/BenchmarkList I suspect that Java Modules is preventing the annotation processor from running properly, but I can't figure out how to fix it. Any ideas?

Undesrtanding Java Serialization

房东的猫 提交于 2019-12-24 00:47:35
问题 I'm trying to compare the standard Java desiralisation. And have a question if it's a correct way to do this. I wrote the following class: //{"first", 1234.1234, 21341234, 234123412341234124L, "fifth"} public class ArrayInputStreamStub extends InputStream{ public int[] arr = new int[260]; private int reader = 0; public ArrayInputStreamStub(){ reader[0] = -84; //... } @Override public int read() throws IOException { return arr[reader++]; } public void reset() { reader = 0; } } I have the same

How to benchmark methods that throw exceptions?

我的未来我决定 提交于 2019-12-24 00:23:11
问题 How is one supposed to benchmark methods that throw exceptions using jmh? I tried the following under jmh 1.19: @Benchmark public void throwException() throws IllegalArgumentException { throw new IllegalArgumentException("Hard-coded exception"); } but got this error: # Run progress: 0.00% complete, ETA 00:02:00 # Fork: 1 of 3 # Warmup Iteration 1: <failure> java.lang.IllegalArgumentException: Hard-coded exception [...] Am I supposed to blackhole exceptions as follows? @Benchmark public void

System.arraycopy with constant length

别说谁变了你拦得住时间么 提交于 2019-12-22 01:53:58
问题 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

Run JMH benchmark under Eclipse

冷暖自知 提交于 2019-12-21 09:24:53
问题 I'm trying to get started with JMH under Eclipse. I can build a jar to execute from the command line but would also like me be able to run it directly within Eclipse for ease of development. Currently I'm getting: java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList I'm using the simple starter case from http://nitschinger.at/Using-JMH-for-Java-Microbenchmarking/: public class MyBenchmark { @Benchmark public void testMethod() { // This is a demo/sample

Benchmarking Java HashMap Get (JMH vs Looping)

拜拜、爱过 提交于 2019-12-21 04:23:07
问题 My ultimate goal is to create a comprehensive set of benchmarks for several Java primitive collection libraries using the standard Java collections as a baseline. In the past I have used the looping method of writing these kinds of micro-benchmarks. I put the function I am benchmarking in a loop and iterate 1 million+ times so the jit has a chance to warmup. I take the total time of the loop and then divide by the number of iterations to get an estimate for the amount of time a single call to

Large performance gap between CPU's div instruction and HotSpot's JIT code

筅森魡賤 提交于 2019-12-21 03:56:29
问题 Since the beginning of CPUs it has been general knowledge that the integer division instruction is expensive. I went to see how bad it is today, on CPUs which have the luxury of billions of transistors. I found that the hardware idiv instruction still performs significantly worse for constant divisors than the code the JIT compiler is able to emit, which doesn't contain the idiv instruction. To bring this out in a dedicated microbenchmark I've written the following: @BenchmarkMode(Mode

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

情到浓时终转凉″ 提交于 2019-12-19 05:06:18
问题 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