Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Special math routines

This topic is 5648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! Do you think, that is a good idea to use spezial optimicsed math routines for amd and intel cups? I have here a little test: for (i = 0; i <= 500000; i++) { sqrtf((float)i); } so i get this result in debugmode (release mode is not ready yet) With math.h: 0.0913186 sec With AMD optimices Code: 0.0703433 sec And my machine: AMD Duron 600 192 MB Ram So is it a good idea to get maximum preformence? Thanks, Christian

Share this post


Link to post
Share on other sites
Advertisement
It''s not such a big performance boost, and it could cause a problem on other machines. If you are the only one who is going to use the program, though, go ahead and use it all you want.

Cédric

Share this post


Link to post
Share on other sites
There are two easy things you can do to speed up the code you describe:

1) compile it in release mode: most compilers only try optimising it if you do so, and/or may add things in debug mode that slow it down. Release mode is usually a lot faster so performnce testing in debug mode is generally pretty pointless.
2) change it to:

float f;
for (f = 0.0f; f <= 500000.0f; f += 1.0f)
{
sqrtf(f);
}

to eliminate the int -> float conversion.

But overall I agree with cedricl: the performance difference is so small that in real code you are unlikely to notice it, and it can make your code far more complex as you perform tests to see what processor you have. Write your code first and examine it with a profier to see where it spends most of it''s time.
Chances are you''ll find the thing that slows it down most is smething completely unexpected.

Share this post


Link to post
Share on other sites
> So is it a good idea to get maximum preformence?
By all means. As johnb says, though, best check if you are compute bound / the float code is a bottleneck.
Do it right, and you can speed things up considerably (one example: 2.5x as fast).

Share this post


Link to post
Share on other sites
quote:
Original post by johnb
float f;
for (f = 0.0f; f <= 500000.0f; f += 1.0f)
{
sqrtf(f);
}

to eliminate the int -> float conversion.



Actually, comparing floats can also be expensive. You can replace it by comparison between integers, using a union of float and int. This works if one of the numbers being compared is positive, because of the internal representation of floats.

Anyway, profile often and check every "optimization" you try, to make sure that it actually makes code faster. Predicting execution times with modern processors is pretty hard, and sometimes an apparently good idea makes your code slower.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!