I wrote a little benchmark that tests performance of java.lang.invoke.MethodHandle
, java.lang.reflect.Method
and direct calls of methods.
I re
If the publicStaticMethod
was a simple implementation like returning a constant, It is very much possible that direct call was in-lined by JIT compiler. This may not be possible with methodHandles.
RE http://vanillajava.blogspot.com/2011/08/methodhandle-performance-in-java-7.html example, as mentioned that comments its not great implementation. if you change the type casting to int (instead of Integer) in the calculation loop, the results are closer to direct method call.
With convoluted implementation of ( creating and calling a future task which returns a random int) gave benchmark with closer numbers where MethodStatic was max ~10% slower than direct method. So you might be seeing 3 times slower performance due to JIT optimizations