Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your experiment is broken, not your laptop. See here for a discussion and some tools to help measure performance: <a href="https://stackoverflow.com/questions/1237181/java-performance-timing-library">Java performance timing library</a></p> <p>Below are some results that contract yours. Also I modified your code to be more rigorous and careful in how it takes measurements.</p> <hr> <p>My environment is Linux (Mint 14 which is based on Ubuntu 12.10) using the Sun JDK 1.6.0_38</p> <p>With 1.5G of heap for the big example, ie -Xmx1512</p> <hr> <p>Note: interesting. Could be my result is different because the array size is different below. Will re-run and update. </p> <p>Nope: the result is similar in there is not much difference in the mean. But what is interesting is the difference against the short run, ie 21092.5 (/10 = 2109.2) vs 1645.2 which may be slower because of memory paging.</p> <p>result with <code>static long[] arr = new long[100000000];</code> (the original array size in question)</p> <blockquote> <p>Write: DescriptiveStatistics: n: 10 min: 20893.0 max: 22190.0 mean: 21092.5 std dev: 390.90727800848117 median: 20953.5 skewness: 3.0092198852491543 kurtosis: 9.264808973899097</p> <p>Read: DescriptiveStatistics: n: 10 min: 21668.0 max: 22736.0 mean: 21892.5 std dev: 318.31509546359877 median: 21766.5 skewness: 2.5034216544466124 kurtosis: 6.560838306717343</p> </blockquote> <hr> <p>I'm not seeing a huge difference in reads vs writes. I changed the experiment to measure 10 times on a slightly smaller array (result is the same number of reads/writes). Feel free to re-run with a larger size array or sample size.</p> <blockquote> <p>Write: DescriptiveStatistics: n: 10 min: 1584.0 max: 1799.0 mean: 1645.2 std dev: 59.51619760853156 median: 1634.5 skewness: 2.137918517160786 kurtosis: 5.764166551997385</p> <p>Read: DescriptiveStatistics: n: 10 min: 1568.0 max: 2202.0 mean: 1689.0 std dev: 186.93908693000031 median: 1623.0 skewness: 2.770215113912315 kurtosis: 8.12245132320571</p> </blockquote> <p>Here is a modified version of your code that does more samples:</p> <pre><code>import java.util.Random; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; public class Test { static Random random = new Random(); // static long[] arr = new long[100000000]; static long[] arr = new long[10000000]; static void seqReadRandWrite() { for (int i = 0; i &lt; arr.length; i++) { int at = Math.abs(random.nextInt()) % arr.length; arr[at] = arr[i]; } } static void seqWriteRandRead() { for (int i = 0; i &lt; arr.length; i++) { int at = Math.abs(random.nextInt()) % arr.length; arr[i] = arr[at]; } } public static void main(String[] args) throws Exception { StopWatch timer = new StopWatch(); int count = 10; // warm up for (int i=0; i&lt;3; i++){ seqReadRandWrite(); } DescriptiveStatistics write = new DescriptiveStatistics(); for (int i=0; i&lt;count; i++){ timer.reset(); timer.start(); seqReadRandWrite(); timer.stop(); write.addValue(timer.getTime()); } System.out.println("Write: " + write); // warm up for (int i=0; i&lt;3; i++){ seqWriteRandRead(); } DescriptiveStatistics read = new DescriptiveStatistics(); for (int i=0; i&lt;count; i++){ timer.reset(); timer.start(); seqWriteRandRead(); timer.stop(); read.addValue(timer.getTime()); } System.out.println("Read: " + read); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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