Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created February 5, 2020 14:21
Show Gist options
  • Save kaityo256/739f6992304c657c68f845461e9ee87d to your computer and use it in GitHub Desktop.
Save kaityo256/739f6992304c657c68f845461e9ee87d to your computer and use it in GitHub Desktop.
Intel Compiler vs. GCC
#include <iostream>
#include <random>
struct myrand {
uint32_t operator()() {
static uint32_t y = 2463534242;
y = y ^ (y << 13); y = y ^ (y >> 17);
return y = y ^ (y << 5);
}
uint32_t max(){
return std::mt19937::max();
}
uint32_t min(){
return 0;
}
};
double run(void) {
myrand mt;
double r = 0.0;
std::uniform_real_distribution<> ud(-1.0, 1.0);
for (int j = 0; j <10000; j++) {
for (int i = 0; i < 10000; i++) {
if (i%2) r += ud(mt);
}
}
return r;
}
int main(){
std::cout << run() << std::endl;
}
@kaityo256
Copy link
Author

Environment

  • CPU: Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz
  • OS: SUSE Linux Enterprise Server 11 (x86_64)
  • g++ (GCC) 5.4.0
  • icpc (ICC) 18.0.5 20180823
$ g++ -O3 -march=native -Wall -Wextra -std=c++11  test.cpp -o gcc.out
$ icpc -O3 -xHOST -Wall -Wextra -std=c++11  test.cpp -o icpc.out
$ time ./gcc.out
-5872.91
./gcc.out  0.26s user 0.00s system 98% cpu 0.259 total

$ time ./icpc.out
-5872.91
./icpc.out  4.52s user 0.00s system 99% cpu 4.526 total

The Intel compiler is 17.5x slower than GCC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment