Using JRE -Xms300m cut my execution time in half?
<p>Greetings all, I was wondering if someone could provide some sort of explaination or confirm my guesses.</p>

<p>I had a program with a for loop which executed several hundred of thousand times, each time adding numbers to a selection of ArrayLists. Confused as to why it was taking so long to execute I investigated further.</p>

<p>It turns out that if I had </p>

<pre><code>(for int i =0; i &lt; 50000; i++)
</code></pre>

<p>It would take almost double the time It would take if I had</p>

<pre><code>(for int i=0; i &lt; 40000; i++)
</code></pre>

<p>Increasing <code>i</code> beyond 50000 even up to 100000 didn't actually take much extra time. There was just this large jump somewhere between 40000 and 50000</p>

<p>Putting my thinking hat on, I gathered that perhaps there was an issue whereby something somewhere was running out of memory? and that more memory had to be make availble, though I'm not sure why it would take so long.</p>

<p>Anyway, I found that by adding the JRE parameter -Xms300m it solved this issue. Am I right in thinking this starts the program with a heap size of 300mb, thus negating the need for extra heap space to be allocated later.</p>

<p>What else I don't understand is that I created memory for the arrayLists which is more than enough. I thought the problem would happen here when I am allocating memory of the heap, not when I use the .add() method.</p>

<pre><code>new ArrayList&lt;Integer&gt;(5000);
</code></pre>
