Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm guessing the reason why it is faster when you are writing into a dataset of 20x2000x2000 is because there are less comparisons and increment/decrements being done. Think of it as a for loop just like the following (2000x2000x20):</p> <pre><code>for (int i = 0; i &lt; 2000; i++) { for (int j = 0; j &lt; 2000; j++) { for (int k = 0; k &lt; 20; k++) { dataset[i][j][k] = data; } } } </code></pre> <p>Number of comparison operations: 88,004,001</p> <p>Number of increment operations: 84,002,000</p> <p>While in the next loop (20x2000x2000):</p> <pre><code>for (int i = 0; i &lt; 20; i++) { for (int j = 0; j &lt; 2000; j++) { for (int k = 0; k &lt; 2000; k++) { dataset[i][j][k] = data; } } } </code></pre> <p>Number of comparison operations:80,040,020</p> <p>Number of increment operations: 80,080,041</p> <p>Thanks to this handy function I made because of this link <a href="http://umencs.blogspot.com/2013/04/optimization-of-nested-for-loops.html" rel="nofollow">http://umencs.blogspot.com/2013/04/optimization-of-nested-for-loops.html</a></p> <pre><code>void ComparisonAndIncrementCount(int nOuterLoop, int nMiddleLoop, int nInnerLoop) { int nComparisonCount = 0; int nIncrementCount = 0; for (int i = 0; (++nComparisonCount) &amp;&amp; i &lt; nOuterLoop; i++, ++nIncrementCount) { for (int j = 0; (++nComparisonCount) &amp;&amp; j &lt; nMiddleLoop; j++, ++nIncrementCount) { for (int k = 0; (++nComparisonCount) &amp;&amp; k &lt; nInnerLoop; k++, ++nIncrementCount) {} } } printf("\n#No. of Increment Operations of Nested For Loop: %d", nIncrementCount); printf("\n#No. of Comparison Operations of Nested For Loop: %d", nComparisonCount); } </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.
    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