title: Performance of new operator versus newInstance() in Java
body: <p>I was using <code>newInstance()</code> in a sort-of performance-critical area of my code.
  The method signature is:</p>
  <p><code>&lt;T extends SomethingElse&gt; T create(Class&lt;T&gt; clasz)</code></p>
  <p>I pass <code>Something.class</code> as argument, I get an instance of <code>SomethingElse</code>, created with <code>newInstance()</code>.</p>
  <p>Today I got back to clear this performance TODO from the list, so I ran a couple of tests of <code>new</code> operator versus <code>newInstance()</code>. I was very surprised with the performance penalty of <code>newInstance()</code>.</p>
  <p>I wrote a little about it, here: <a href="http://biasedbit.com/blog/new-vs-newinstance/" rel="nofollow noreferrer">http://biasedbit.com/blog/new-vs-newinstance/</a></p>
  <p>(Sorry about the self promotion... I'd place the text here, but this question would grow out of proportions.)</p>
  <p>What I'd love to know is why does the <code>-server</code> flag provide such a performance boost when the number of objects being created grows largely and not for &quot;low&quot; values, say, 100 or 1000.</p>
  <p>I did learn my lesson with the whole reflections thing, this is just curiosity about the optimisations the JVM performs in runtime, especially with the <code>-server</code> flag. Also, if I'm doing something wrong in the test, I'd appreciate your feedback!</p>
  <hr />
  <p>Edit: I've added a warmup phase and the results are now more stable. Thanks for the input!</p>