title: Java Performance measurement
body: <p>I am doing some Java performance comparison between my classes, and wondering if there is some sort of Java Performance Framework to make writing performance measurement code easier?</p>
  
  <p>I.e, what I am doing now is trying to measure what effect does it have having a method as "synchronized" as in PseudoRandomUsingSynch.nextInt() compared to using an AtomicInteger as my "synchronizer".</p>
  
  <p>So I am trying to measure how long it takes to generate random integers using 3 threads accessing a synchronized method looping for say 10000 times.</p>
  
  <p>I am sure there is a much better way doing this. Can you please enlighten me? :)</p>
  
  <pre><code>public static void main( String [] args ) throws InterruptedException, ExecutionException {
      PseudoRandomUsingSynch rand1 = new PseudoRandomUsingSynch((int)System.currentTimeMillis());
      int n = 3;
      ExecutorService execService = Executors.newFixedThreadPool(n);
  
      long timeBefore = System.currentTimeMillis();
      for(int idx=0; idx&lt;100000; ++idx) {
          Future&lt;Integer&gt; future = execService.submit(rand1);
          Future&lt;Integer&gt; future1 = execService.submit(rand1);
          Future&lt;Integer&gt; future2 = execService.submit(rand1);
  
          int random1 = future.get();
          int random2 = future1.get();
          int random3 = future2.get();
  
      }
      long timeAfter = System.currentTimeMillis();
      long elapsed = timeAfter - timeBefore;
      out.println("elapsed:" + elapsed);
  }
  </code></pre>
  
  <p>the class</p>
  
  <pre><code>public class PseudoRandomUsingSynch implements Callable&lt;Integer&gt; {
  private int seed;
  
  public PseudoRandomUsingSynch(int s) { seed = s; }
  
  public synchronized int nextInt(int n) {
      byte [] s = DonsUtil.intToByteArray(seed);
      SecureRandom secureRandom = new SecureRandom(s);
      return ( secureRandom.nextInt() % n );
  }
  
  @Override
  public Integer call() throws Exception {
      return nextInt((int)System.currentTimeMillis());
  }
  }
  </code></pre>
  
  <p>Regards</p>