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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

SQL Server - MyCTE query based on 24 hour period (next day) -

php - Using str_replace to translate a MySQL Table in html -