Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created February 5, 2020 14:36
Show Gist options
  • Save kaityo256/d41481467df504c5039715d38954ab8a to your computer and use it in GitHub Desktop.
Save kaityo256/d41481467df504c5039715d38954ab8a to your computer and use it in GitHub Desktop.
Intel Compiler vs. GCC
#include <iostream>
#include <random>
struct myrand {
uint32_t operator()() {
return 0;
}
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

Thanks @dc1394. That's interesting.

In that sense, we should say "GCC generates faster executables" instead of "Intel compiler generates slower ones"...

@uTnOJkji5quPSNE5
Copy link

I think this code doesn't measure the code-gen quality of those two compilers but compares the performance of the Mersenne twister implementation and tuning...

@kaityo256
Copy link
Author

Yep, you are right, @uTnOJkji5quPSNE5.

I should say, "the Mersenne Twister implementation included in GCC was fast". Anyway, I'm not sure why.

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