jmh - How to benchmark methods that throw exceptions? -


how 1 supposed benchmark methods throw exceptions using jmh?

i tried following under jmh 1.19:

@benchmark public void throwexception() throws illegalargumentexception {   throw new illegalargumentexception("hard-coded exception"); } 

but got 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 supposed blackhole exceptions follows?

@benchmark public void throwexception(blackhole bh) {     try     {         throw new illegalargumentexception("hard-coded exception");     }     catch (illegalargumentexception e)     {         bh.consume(e);     } } 

or there way tell jmh accept thrown exceptions?

summarizing answers i've received i've received kiril s. , oleg estekhin:

jmh fail if benchmark method throws exception. correct this, benchmark method must catch exception. can consume exception using blackhole object, or return benchmark method. prevent compiler optimizing-away throw statement.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -