For Programmers: Free Programming Magazines  


Home > Archive > Extreme Programming > May 2004 > Optimize these 2 lines of code!!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Optimize these 2 lines of code!!
Tan Thuan Seah

2004-05-24, 6:35 am

Hi all,

I am working on an assignment and i hope to optimize the following two
lines of code for a Ultrasparc II machine. The code is running in a loop for
about 100000 iterations.

dist2 = a*a + b*b + c*c;
dist = sqrt(dist2);
d = 12.0/pow(dist, 14.0) - 12.0/pow(dist, 8..0);
pe+= 1.0/pow(dist, 12) - 2.0/pow(dist, 6.0);

i have change it to:

dist2 = a*a+b*b+c*c;
e = dist2 * dist2 *dist2; // to get the same as pow(dist, 6.0)
f = e * e * dist2; // to get the same as pow(dist, 14.0)
d = (12.0 - 12.0*e)/f; // most expensive computation in the loop
<-- the 2 lines of code starts here
pe += (1.0 - 2.0*e)/(e*e) // next most expensive computation in the loop

But this is still not producing the speed i am expecting. What else can i do
to optimise? Thx for any hints and advice.

Thuan Seah


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com