I noticed that the following code is extremely slow to compile: (It can't even finish on my computer)
#include <complex>
struct some_big_struct {
std::complex <double> a[1000000][2];
};
some_big_struct a;
int main () {
return 0;
}
Out of curiosity, I've also tried other alternatives of the code. However, these codes seem to compile just fine on my computer :
#include <complex>
struct some_big_struct {
double a[1000000][2];
};
some_big_struct a;
int main () {
return 0;
}
and
#include <complex>
std::complex <double> a[1000000][2];
int main () {
return 0;
}
I wonder if anyone can share some insight on why such is the case. Thanks!
The compiler is probably running the default std::complex constructor while compiling, so that it can put the initialized values of all the array members into the executable, rather than generate code that performs this loop when the program starts. So it's calling the constructor 2 million times while compiling.
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