I don't know about Java but in .NET there's a call you can make to force the dynamically generated lamba expression to be compiled immediately.
Of course if you're being really adventurous you can use IL emit to build a function up from IL opcodes.
I don't know about Java but in .NET there's a call you can make to force the dynamically generated lamba expression to be compiled immediately.
Of course if you're being really adventurous you can use IL emit to build a function up from IL opcodes.
http://openjdk.java.net/projects/code-tools/jmh/
It takes care of details like JVM warm-ups. ensuring sufficient invocations for JIT compilation to have occurred, etc.
Testing with CompilerControl.Mode.EXCLUDE in JMH is still more reliable than testing manually, when you don't know if it got compiled or not.
Interpreted code is a case where method handles should be much faster than the generated accessor classes used by reflection - lambdas and method references are faster than an inner class implementing a functional interface before jit compilation. Afterwards, performance tends to be sameish.
I came across some code a few weeks ago that skipped this step. It wasn't called remotely often enough to justify the complication in the first place (low volume internal web app) but it didn't cache the result so it ended up making things slower. Thanks to the wonders of RenderAction in MVC it compiled the dynamic IL 20 times per page view as well.