Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can take timestamp snapshots before and after, then <strong>repeat the experiments several times to average to results</strong>. There are also profilers that can do this for you.</p> <hr> <h2>From "Java Platform Performance: Strategies and Tactics" book:</h2> <p><strong>With System.currentTimeMillis()</strong></p> <pre><code>class TimeTest1 { public static void main(String[] args) { long startTime = System.currentTimeMillis(); long total = 0; for (int i = 0; i &lt; 10000000; i++) { total += i; } long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; System.out.println(elapsedTime); } } </code></pre> <p><strong>With a StopWatch class</strong></p> <p>You can use this <code>StopWatch</code> class, and call <code>start()</code> and <code>stop</code> before and after the method.</p> <pre><code>class TimeTest2 { public static void main(String[] args) { Stopwatch timer = new Stopwatch().start(); long total = 0; for (int i = 0; i &lt; 10000000; i++) { total += i; } timer.stop(); System.out.println(timer.getElapsedTime()); } } </code></pre> <p>See <a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPMeasurement.fm.html" rel="noreferrer">here</a>.</p> <hr> <h2>NetBeans Profiler:</h2> <blockquote> <p><strong>Application Performance Application</strong></p> <p>Performance profiles <strong>method-level CPU performance (execution time)</strong>. You can choose to profile the entire application or a part of the application.</p> </blockquote> <p>See <a href="http://profiler.netbeans.org/docs/help/5.5/profile_analyze_short.html" rel="noreferrer">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload