I have a piece of code that runs 2x faster on windows than on linux. Here are the times I measured:
g++ -Ofast -march=native -m64
29.1123
g++ -Ofast -march=native
29.0497
clang++ -Ofast -march=native
28.9192
visual studio 2013 Debug 32b
13.8802
visual studio 2013 Release 32b
12.5569
It really seems to be too huge a difference.
Here is the code:
#include <iostream>
#include <map>
#include <chrono>
static std::size_t Count = 1000;
static std::size_t MaxNum = 50000000;
bool IsPrime(std::size_t num)
{
for (std::size_t i = 2; i < num; i++)
{
if (num % i == 0)
return false;
}
return true;
}
int main()
{
auto start = std::chrono::steady_clock::now();
std::map<std::size_t, bool> value;
for (std::size_t i = 0; i < Count; i++)
{
value[i] = IsPrime(i);
value[MaxNum - i] = IsPrime(MaxNum - i);
}
std::chrono::duration<double> serialTime = std::chrono::steady_clock::now() - start;
std::cout << "Serial time = " << serialTime.count() << std::endl;
system("pause");
return 0;
}
All of this was measured on the same machine with windows 8 vs linux 3.19.5(gcc 4.9.2, clang 3.5.0). Both linux and windows are 64bit.
What could be the reason for this? Some scheduler issues?
Simply put, a 64-bit processor is more capable than a 32-bit processor because it can handle more data at once. A 64-bit processor can store more computational values, including memory addresses, which means it can access over 4 billion times the physical memory of a 32-bit processor. That's just as big as it sounds.
Architecture: x86_64 – Linux kernel is 62 bit. CPU op-mode(s): 32-bit, 64-bit – Your CPU can run 32 or 64 bit instructions i.e. Linux kernel.
Windows 10 64-bit has better performance and more features. But if you run older hardware and software, Windows 10 32-bit might be a better choice. Windows 10 comes in two architectures: 32-bit and 64-bit.
Linux Mint Debian Edition It is equally easy to use and as reliable as Linux Mint based on Ubuntu. Not just limited to the Debian base, but you get support for both 64-bit and 32-bit systems. This should be a great choice if you do not want to use a Linux distribution that you've never heard on your 32-bit system.
You don't say whether the windows/linux operating systems are 32 or 64 bit.
On a 64-bit linux machine, if you change the size_t to an int you'll find that execution times drop on linux to a similar value to those that you have for windows.
size_t is an int32 on win32, an int64 on win64.
EDIT: just seen your windows disassembly.
Your windows OS is the 32-bit variety (or at least you've compiled for 32-bit).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With