Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Programmer Help > Re: float vs. d...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 10 Topic 3779 of 3882
Post > Topic >>

Re: float vs. double

by Reinder Verlinde <reinder@[EMAIL PROTECTED] > Jun 23, 2008 at 06:56 PM

In article 
<0c2cd374-bfef-468f-ba36-de61bd9b408f@[EMAIL PROTECTED]
>,
 MacRules <dodeca001@[EMAIL PROTECTED]
> wrote:

> <snip>
> Sorry - stupid mistake. I took a look at the ASM code - the compiler
> optimizer was smart enough to figure out that the variables inside
> these loops aren't used for anything, and deleted them. However, the
> optimizer wasn't smart enough to figure out that the resulting empty
> FOR loops aren't doing anything, either, so it left these in.
> 
> I added some printf() calls to be bottom of the function, making all
> of the variables above 'relevant' and thus forcing the optimizer to
> leave the FOR loop contents intact:
> 
> printf("a_f b_f c_f d_f e_f f_f = %f %f %f %f %f %f
> \n",a_f,b_f,c_f,d_f,e_f,f_f);
> printf("a_d b_d c_d d_d e_d f_d = %lf %lf %lf %lf %lf %lf
> \n",a_d,b_d,c_d,d_d,e_d,f_d);
> 
> I then verified that the compiler is now doing the requested
> mathematical operations with floats and doubles.
> 
> The new results:
> 
> Number of iterations? 50000000
> 
> Duration float, double = 643 361 ms
> 
> I don't know why double would be twice as fast as float
> [...]
> In any case, my original conclusion still holds: I should upgrade
> to double.

Based on what you told here, I would not conclude that. Your logic still 
may be flawed. I would guess that, if you changed your code to read and 
write lots of different memory locations, you could reverse the timing 
difference.

For example,

   float * a_fs = new float[1000000];
   float * b_fs = new float[1000000];
   float * c_fs = new float[1000000];
   ...
   for( int i = 0; i < 1000000; ++i) {
     c_fs[i] = a_fs[i] * b_fs[ i];
   }

Reason would be that, for this, the number of bytes that have to be read 
and written will be the limiting factors in the speed you get.

I haven't checked, but there also may be effects of the placement of 
your variables in cache lines.

Reinder
 




 10 Posts in Topic:
float vs. double
MacRules <dodeca001@[E  2008-06-22 09:37:54 
Re: float vs. double
MacRules <dodeca001@[E  2008-06-22 19:55:39 
Re: float vs. double
Gregory Weston <uce@[E  2008-06-22 23:42:28 
Re: float vs. double
Reinder Verlinde <rein  2008-06-23 18:56:28 
Re: float vs. double
MacRules <dodeca001@[E  2008-06-23 05:31:21 
Re: float vs. double
MacRules <dodeca001@[E  2008-06-23 18:32:47 
Re: float vs. double
Korchkidu <korchkidu@[  2008-06-24 07:55:57 
Re: float vs. double
MacRules <dodeca001@[E  2008-06-24 09:39:46 
Re: float vs. double
Korchkidu <korchkidu@[  2008-06-29 08:14:36 
Re: float vs. double
glenn andreas <gandrea  2008-06-29 10:35:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 11:25:01 CST 2008.