Posted By: cro | Nov 3rd @ 10:36 AM
page 1 of 1
Comments: 6 | Views: 292
cro
cro

I'm running some test in C++ to be sure that our program run in x86 and x64. I was really surprise to notice a speed improvement in x64. I'm running the test on a Win7 x64 machine. Is the x64 is faster because it is running on a 64 OS ? Or is it something in the code that is better in x64 ? I'm using VS 2008.

 

#include <iostream> 
#include <ctime> 

using namespace std; 

#define ROWS 2000 
#define COLS 2000 
#define LOOP 100 

int main() 
{ 
   float* m = new float[ROWS * COLS]; 
   time_t begin, end; 
   time(&begin); 

   for (int n = 0; n < LOOP; ++n) 
   { 
      for (size_t row = 0; row < ROWS; ++row) 
      { 
         for (size_t col = 0; col < COLS; ++col) 
         { 
            m[row * COLS + col] = 1.0f * (rand() % 1000); 
         } 
      } 
   } 
   time(&end); double elapse = difftime(end, begin); 
   cout << "Done in " << elapse << " seconds" << endl; 

   delete[] m; 
} 

 

That simple test took 12 seconds in x86 and only 8 seconds in x64. Repro or explanation anyone ?

 

Thanks.

I imagine it's faster because it doesn't have to run through the WoW emulator. How does it run if you install Win7 x86 and run the program?

W3bbo
W3bbo
The Master of Baiters

WOW won't affect the speed of a program's internals, only calls to Win32 functions that are sandboxed for 32-bit applications. WOW64 is only an emulator on the IA64 platform, not x64. One of the key advantages of the x64 design is that the speed of x86 applications isn't affected at all.

 

The speed increase could be down to any number of reasons, you'll have to dual-boot your system with an x86 OS and re-run the rest there to get a true comparison. Personally I'd put it down to better optimisation on x64 to take advantage of newer instructions.

Keep in mind that x64 has more registers (it is more likely that all the 3 loop variables will end up in registers on x64) and that all x64 CPUs have SSE and the compiler will use that. Try enabling SSE/SSE2 when compiling for x86, see if it makes a difference.

 

Though the difference in performance seems rather big for such simple code. Try without rand(), maybe the x86 implementation is slower.

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

I tried it without rand, the difference between x86 and x64 was minimal. So it does appear to be that rand is where the difference lies, rather than in cro's code.

page 1 of 1
Comments: 6 | Views: 292
Microsoft Communities