| re: std::complex
>> I found out that default constructor of std::complex class initializes[color=blue][color=green]
>> the value to (0,0). I wonder why is it so?
>> Because of this, the code below is about two times slower than it could
>> be if the default constructor left the values uninitialized.[/color][/color]
[color=blue]
>How have you managed to time that, or is it just a guess?[/color]
I have generated an assembly listing on MSVC .NET 2003 all optimizations
enabled. Here's the function:
#include <complex>
std::complex<float> f()
{
std::complex<float> c[100];
for (int i = 0; i < 100; ++i)
c[i] = std::complex<float>(1, 0);
return c[50];
}
Below is a relevant part of assembly listing for the function f. Note the
loop that is created by line #5 (the definition of the array):
; 5 : std::complex<float> c[100];
lea eax, DWORD PTR _c$[esp+800]
mov ecx, 100 ; 00000064H
xor edx, edx
$L11604:
mov DWORD PTR [eax], edx
mov DWORD PTR [eax+4], edx
add eax, 8
sub ecx, 1
jne SHORT $L11604
; 6 : for (int i = 0; i < 100; ++i)
xor eax, eax
mov ecx, 1065353216 ; 3f800000H
$L10133:
; 7 : c[i] = std::complex<float>(1, 0);
mov DWORD PTR _c$[esp+eax*8+800], ecx
mov DWORD PTR _c$[esp+eax*8+804], edx
add eax, 1
cmp eax, 100 ; 00000064H
jl SHORT $L10133
Best regards,
Marcin |