Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have nothing substantial to add to ruakh's answer, but here's a quick test function. I keep a scrap project around for writing little tests like these. Adjust the sourceSize to something representative of your data, and you can get a rough idea of the magnitude of the effect. As shown, I saw about a factor of 2 between them. </p> <pre><code>import java.util.ArrayList; import java.util.Random; public class ALTest { public static long fill(ArrayList&lt;Byte&gt; al, byte[] source) { long start = System.currentTimeMillis(); for (byte b : source) { al.add(b); } return System.currentTimeMillis()-start; } public static void main(String[] args) { int sourceSize = 1&lt;&lt;20; // 1 MB int smallIter = 50; int bigIter = 4; Random r = new Random(); byte[] source = new byte[sourceSize]; for (int i = 0;i&lt;bigIter;i++) { r.nextBytes(source); { long time = 0; for (int j = 0;j&lt;smallIter;j++) { ArrayList&lt;Byte&gt; al = new ArrayList&lt;Byte&gt;(sourceSize); time += fill(al,source); } System.out.print("With: "+time+"ms\t"); } { long time = 0; for (int j = 0;j&lt;smallIter;j++) { ArrayList&lt;Byte&gt; al = new ArrayList&lt;Byte&gt;(); time += fill(al,source); } System.out.print("Without: "+time+"ms\t"); } { long time = 0; for (int j = 0;j&lt;smallIter;j++) { ArrayList&lt;Byte&gt; al = new ArrayList&lt;Byte&gt;(); time += fill(al,source); } System.out.print("Without: "+time+"ms\t"); } { long time = 0; for (int j = 0;j&lt;smallIter;j++) { ArrayList&lt;Byte&gt; al = new ArrayList&lt;Byte&gt;(sourceSize); time += fill(al,source); } System.out.print("With: "+time+"ms"); } System.out.println(); } } } </code></pre> <p>Output:</p> <pre><code>With: 401ms Without: 799ms Without: 731ms With: 347ms With: 358ms Without: 744ms Without: 749ms With: 342ms With: 348ms Without: 719ms Without: 739ms With: 347ms With: 339ms Without: 734ms Without: 774ms With: 358ms </code></pre>
 

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