Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Laurent Desnogues <Laurent.Desnogues@ar...>  20060321 09:03:46

> > int main(void){ > > double d =3D 1.0; > > double i =3D 1.0; > > > > for(; i < 100000000; i +=3D 1.0){ > > d =3D d * i; > > d =3D 1.0; > > } > > } This test is dumb, the multiplication is removed :) If you enable optimizations only a double add and a double comparison will remain. On top of that, depending on the kind of task doubles are not needed, floats are enough. Laurent  IMPORTANT NOTICE: The contents of this email and any attachments are = confidential and may also be privileged. If you are not the intended = recipient, please notify the sender immediately and do not disclose the = contents to any other person, use it for any purpose, or store or copy = the information in any medium. Thank you. 
From: Craig Hughes <craig@gu...>  20060321 09:16:25

On Mar 21, 2006, at 1:03 AM, Laurent Desnogues wrote: >>> int main(void){ >>> double d = 1.0; >>> double i = 1.0; >>> >>> for(; i < 100000000; i += 1.0){ >>> d = d * i; >>> d = 1.0; >>> } >>> } > > This test is dumb, the multiplication is removed :) > If you enable optimizations only a double add and a > double comparison will remain. > > On top of that, depending on the kind of task > doubles are not needed, floats are enough. Actually, looking at the generated code with objdump, it's pretty clear that since the value of d is never referenced, it basically just optimized more or less the whole thing inside the loop away. C 
From: Craig Hughes <craig@gu...>  20060321 09:22:44

On Mar 21, 2006, at 1:16 AM, Craig Hughes wrote: > On Mar 21, 2006, at 1:03 AM, Laurent Desnogues wrote: > >>>> int main(void){ >>>> double d = 1.0; >>>> double i = 1.0; >>>> >>>> for(; i < 100000000; i += 1.0){ >>>> d = d * i; >>>> d = 1.0; >>>> } >>>> } >> >> This test is dumb, the multiplication is removed :) >> If you enable optimizations only a double add and a >> double comparison will remain. >> >> On top of that, depending on the kind of task >> doubles are not needed, floats are enough. > > Actually, looking at the generated code with objdump, it's pretty > clear that since the value of d is never referenced, it basically > just optimized more or less the whole thing inside the loop away. Doing this instead: int main (void) { double d = 1.0; double i = 1.0; for (; i < 100000000; i += 1.0) { d = d * i; } printf("Result is: %f\n",d); } yields: # time ./mult Result is: inf Command exited with nonzero status 15 real 0m 54.74s user 0m 54.39s sys 0m 0.00s and: int main (void) { double d = 1.0; double i = 1.0; for (; i < 100000000; i += 1.0) { d = d * i; d = d / i; } printf("Result is: %f\n",d); } (in case exceeding inf causes mults to just shortcircuit at some point) yields: # time ./mult Result is: 1.000000 Command exited with nonzero status 20 real 1m 50.60s user 1m 49.76s sys 0m 0.01s 
From: Mark Goldman <bitshifter@gm...>  20060321 20:43:56

Thank you very much, I appreciate you taking the time to look at this for m= e. > >> This test is dumb, the multiplication is removed :) > >> If you enable optimizations only a double add and a > >> double comparison will remain. I didn't actually expect it to be compiled with optimization, I guess I should have specified that :) > >> On top of that, depending on the kind of task > >> doubles are not needed, floats are enough. I understand in many cases floats are enough, however the control code that I am implementing actually does need the precision in most cases. I know that all benchmarks are wrong in general, however in my case 90% of the time is spent doing double maths so this particular case is of use to me. > > Actually, looking at the generated code with objdump, it's pretty > > clear that since the value of d is never referenced, it basically > > just optimized more or less the whole thing inside the loop away. > > Doing this instead: > > int > main (void) > { > double d =3D 1.0; > double i =3D 1.0; > > for (; i < 100000000; i +=3D 1.0) > { > d =3D d * i; > } > printf("Result is: %f\n",d); > } > > yields: > > # time ./mult > Result is: inf > Command exited with nonzero status 15 > real 0m 54.74s > user 0m 54.39s > sys 0m 0.00s > > and: > > int > main (void) > { > double d =3D 1.0; > double i =3D 1.0; > > for (; i < 100000000; i +=3D 1.0) > { > d =3D d * i; > d =3D d / i; > } > printf("Result is: %f\n",d); > } > > (in case exceeding inf causes mults to just shortcircuit at some point) > yields: > > # time ./mult > Result is: 1.000000 > Command exited with nonzero status 20 > real 1m 50.60s > user 1m 49.76s > sys 0m 0.01s Thank you, Craig, for rerunning the tests. I appreciate it. mdg 