Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my loop slower when I remove code
    text
    copied!<p>When I remove the tests to compute minimum and maximum from the loop, the execution time is actually longer than with the test. How is that possible ? </p> <p>Edit : After running more test, it seems the runtime is not constant, ie the same code can run in 9 sec or 13 sec.... So it was just a repetable coincidence. Repetable until you do enough tests that is...</p> <p>Some details :</p> <ul> <li>execution time with the min max test : 9 sec</li> <li>execution time without the min max test : 13 sec</li> <li><code>CFLAGS=-Wall -O2 -fPIC -g</code></li> <li>gcc 4.4.3 32 bit Section to remove is now indicated in code</li> </ul> <p>Some guess : bad cache interaction ?</p> <pre><code>void FillFullValues(void) { int i,j,k; double X,Y,Z; double p,q,r,p1,q1,r1; double Ls,as,bs; unsigned long t1, t2; t1 = GET_TICK_COUNT(); MinLs = Minas = Minbs = 1000000.0; MaxLs = Maxas = Maxbs = 0.0; for (i=0;i&lt;256;i++) { for (j=0;j&lt;256;j++) { for (k=0;k&lt;256;k++) { X = 0.4124*CielabValues[i] + 0.3576*CielabValues[j] + 0.1805*CielabValues[k]; Y = 0.2126*CielabValues[i] + 0.7152*CielabValues[j] + 0.0722*CielabValues[k]; Z = 0.0193*CielabValues[i] + 0.1192*CielabValues[j] + 0.9505*CielabValues[k]; p = X * InvXn; q = Y; r = Z * InvZn; if (q&gt;0.008856) { Ls = 116*pow(q,third)-16; } else { Ls = 903.3*q; } if (q&lt;=0.008856) { q1 = 7.787*q+seiz; } else { q1 = pow(q,third); } if (p&lt;=0.008856) { p1 = 7.787*p+seiz; } else { p1 = pow(p,third); } if (r&lt;=0.008856) { r1 = 7.787*r+seiz; } else { r1 = pow(r,third); } as = 500*(p1-q1); bs = 200*(q1-r1); // // cast on short int for reducing array size // FullValuesLs[i][j][k] = (char) (Ls); FullValuesas[i][j][k] = (char) (as); FullValuesbs[i][j][k] = (char) (bs); //// Remove this and get slower code if (MaxLs&lt;Ls) MaxLs = Ls; if ((abs(Ls)&lt;MinLs) &amp;&amp; (abs(Ls)&gt;0)) MinLs = Ls; if (Maxas&lt;as) Maxas = as; if ((abs(as)&lt;Minas) &amp;&amp; (abs(as)&gt;0)) Minas = as; if (Maxbs&lt;bs) Maxbs = bs; if ((abs(bs)&lt;Minbs) &amp;&amp; (abs(bs)&gt;0)) Minbs = bs; //// End of Remove } } } TRACE(_T("LMax = %f LMin = %f\n"),(MaxLs),(MinLs)); TRACE(_T("aMax = %f aMin = %f\n"),(Maxas),(Minas)); TRACE(_T("bMax = %f bMin = %f\n"),(Maxbs),(Minbs)); t2 = GET_TICK_COUNT(); TRACE(_T("WhiteBalance init : %lu ms\n"), t2 - t1); } </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