Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy c++ program compiled for x64 platform is slower than compiled for x86?
    text
    copied!<p>I've wrote program, and compiled it for x64 and x86 platform in Visual Studio 2010 on Intel Core i5-2500. x64 version take about 19 seconds for execution and x86 take about 17 seconds. What can be the reason of such behavior?</p> <pre><code>#include "timer.h" #include &lt;vector&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;string&gt; #include &lt;sstream&gt; /********************DECLARATIONS************************************************/ class Vector { public: Vector():x(0),y(0),z(0){} Vector(double x, double y, double z) : x(x) , y(y) , z(z) { } double x; double y; double z; }; double Dot(const Vector&amp; a, const Vector&amp; b) { return a.x * b.x + a.y * b.y + a.z * b.z; } class Vector2 { public: typedef double value_type; Vector2():x(0),y(0){} Vector2(double x, double y) : x(x) , y(y) { } double x; double y; }; /******************************TESTS***************************************************/ void Test(const std::vector&lt;Vector&gt;&amp; m, std::vector&lt;Vector2&gt;&amp; m2) { Vector axisX(0.3f, 0.001f, 0.25f); Vector axisY(0.043f, 0.021f, 0.45f); std::vector&lt;Vector2&gt;::iterator i2 = m2.begin(); std::for_each(m.begin(), m.end(), [&amp;](const Vector&amp; v) { Vector2 r(0,0); r.x = Dot(axisX, v); r.y = Dot(axisY, v); (*i2) = r; ++i2; }); } int main() { cpptask::Timer timer; int len2 = 300; size_t len = 5000000; std::vector&lt;Vector&gt; m; m.reserve(len); for (size_t i = 0; i &lt; len; ++i) { m.push_back(Vector(i * 0.2345, i * 2.67, i * 0.98)); } /***********************************************************************************/ { std::vector&lt;Vector2&gt; m2(m.size()); double time = 0; for (int i = 0; i &lt; len2; ++i) { timer.Start(); Test(m, m2); time += timer.End(); } std::cout &lt;&lt; "Dot product double - " &lt;&lt; time / len2 &lt;&lt; std::endl; } /***********************************************************************************/ return 0; } </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