I want to make a sin func. so here’s my code:
inline double _cdecl Sin(double Rad)
{
_asm
{
fld QWORD PTR [Rad]
fsin
}
}
my func works faster(ratio of about 6) than the standard sin. (there are probably some problems in it, but it’s enough for me)
but if I’ll do for example
for(int i = 0; i < 1000000; ++i)
sin(1)
the standard sin will be faster in a ratio of about 3
and if I’ll do
for(int i = 0; i < 1000000; ++i)
sin(i)
my func will be faster in ratio of about 3.
what happens here?
The compiler might know that
sin(1)is an intrinsic pure function with no side effects, and therefore won’t even bother to call it within the loop. So you might end up just timing the loop itself. Check the generated assembly code using the appropriate compiler switch for assembly output.