compare - Benchmarking in Java (comparing two classes) -


i'll want compare speed of work 2 classes (stringbuider , stringbuffer) using append method.

and wrote simple program:

public class test {     public static void main(string[] args) {         try {             test(new stringbuffer("")); // stringbuffer: 35117ms.             test(new stringbuilder("")); // stringbuilder: 3358ms.         } catch (ioexception e) {             system.err.println(e.getmessage());         }     }     private static void test(appendable obj) throws ioexception {         long before = system.currenttimemillis();         (int = 0; i++ < 1e9; ) {             obj.append("");         }         long after = system.currenttimemillis();         system.out.println(obj.getclass().getsimplename() + ": " +                           (after - before) + "ms.");     } } 

but know, it's bad way benchmarking. want put annotations on method or class, set number of iterations, tests, different conditions , @ output accurate results.

please advise good library or standard java tools solve problem. additionally, if not difficult, write benchmarking.

thanks in advance!

jmh, java microbenchmark harness, allows run correct micro benchmarks. uses annotations express benchmark parameters.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -