Deoptimizing a C++ program
I&#x27;m finding this more difficult than I expected, at least if I interpret the problem as finding &quot;deoptimizations&quot; that are specific to modern Intel processors.  Finding ways to slow things down through changing the algorithm, increasing precision, or adding unnecessary work are easy, but I haven&#x27;t yet found anything that would be a plausible optimization made by a beginning programmer that hurts performance more on modern Intel than would be expected.<p>In the answers, I think Peter covers most of the likely attacks.  One that isn&#x27;t mentioned is &quot;choosing the wrong compiler&quot;.  Not just compiler options, but compiler.  While there isn&#x27;t a &quot;best&quot; compiler for everything, for a given program often one will perform better than the others.  Especially if one is targetting recent Intel CPUs, Intel&#x27;s compiler can occasionally beat GCC and Clang by surprisingly large amounts.  This appears to be one of those times.<p>Here are the times I see for for this example on a 3.4 GHz Skylake running 64-bit Linux when compiled with different modern compilers:<p><pre><code>  icpc 16.03:  0.87 s
  clang++ 3.8: 1.76 s
  g++ 5.3.0:   1.73 s
</code></pre>
All were compiled with &quot;-march=native -g -Ofast&quot;, which I think causes all of the compilers to use the equivalent of &quot;-ffast-math&quot;.  At least, I&#x27;m pretty sure icpc uses it by default, and I didn&#x27;t see any difference in performance when I added &quot;-ffast-math&quot; or &quot;-funsafe-math-optimizations&quot; to clang++ and g++.  So in this case, I (provocatively) would suggest that using clang++ or g++ would be a subtle 2x deoptimization.  There are definitely reasons to prefer them, but for this example that choice looks to come at a large cost in performance.<p>If you want to do your own comparison, Version 17 of the Intel compiler is currently available as a free beta for Windows, Mac, and Linux: <a href="https:&#x2F;&#x2F;software.intel.com&#x2F;en-us&#x2F;articles&#x2F;intel-parallel-studio-xe-2017-beta" rel="nofollow">https:&#x2F;&#x2F;software.intel.com&#x2F;en-us&#x2F;articles&#x2F;intel-parallel-stu...</a>.  I don&#x27;t know how they are defining the license duration, but when I downloaded yesterday it gave me a license valid until October 2016.  Separately, I&#x27;d be interested to see what MSVC does with this on a comparable machine.