Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just to further reiterate how important performance testing is I ran the following test on my Core i5-750 in 64-bit native and 32-bit mode on Windows 7 compiled with VS 2010 targetting .NET 4.0 and got the following results:</p> <pre><code> public static bool DoSomething(double[] args) { bool ret = false; for (int i = 0; i &lt; args.Length; i++) { if (double.IsNaN(args[i])) { ret = !ret; } } return ret; } public static bool DoSomething2(double[] args) { bool ret = false; for (int i = 0; i &lt; args.Length; i++) { if (args[i] != args[i]) { ret = !ret; } } return ret; } public static IEnumerable&lt;R&gt; Generate&lt;R&gt;(Func&lt;R&gt; func, int num) { for (int i = 0; i &lt; num; i++) { yield return func(); } } static void Main(string[] args) { Random r = new Random(); double[] data = Generate(() =&gt; { var res = r.NextDouble(); return res &lt; 0.5 ? res : Double.NaN; }, 1000000).ToArray(); Stopwatch sw = new Stopwatch(); sw.Start(); DoSomething(data); Console.WriteLine(sw.ElapsedTicks); sw.Reset(); sw.Start(); DoSomething2(data); Console.WriteLine(sw.ElapsedTicks); Console.ReadKey(); } </code></pre> <p>In x86 mode (Release, naturally):</p> <pre><code>DoSomething() = 139544 DoSomething2() = 137924 </code></pre> <p>In x64 mode:</p> <pre><code>DoSomething() = 19417 DoSomething2() = 17448 </code></pre> <p>However, something interesting happens if our distribution of <code>NaN</code>'s is sparser. If we change our <code>0.5</code> constant to <code>0.9</code> (only 10% NaN's) we get:</p> <p>x86:</p> <pre><code>DoSomething() = 31483 DoSomething2() = 31731 </code></pre> <p>x64:</p> <pre><code>DoSomething() = 31432 DoSomething2() = 31513 </code></pre> <p>Reordering the calls shows the same trend as well. Food for thought.</p>
 

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