Advertisement

Tute #11

Started by December 20, 2002 11:08 PM
3 comments, last by Ronin Magus 22 years, 2 months ago
I don''t know if this has been touched on in another post (the search feature is still disabled..) but in Bosco''s tutorial #11 on Nehe, you can gain a bit of a performance boost in the initialization routine.
  
//Change this line:

points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f));

//into this:

points[x][y][2] = float(sin((x/45.0) * 6.283185308));
  
I can only assume this was left unoptimized since it''s a part of initialization and therefore isn''t as important as optimizing an algorithm in the main runtime loop, or maybe to emphasize the division by 360 and multiply by 2pi for the radian/phase reasons. But even so, a good algorithm is a simplified one And this changes it from 2 divisions and 3 multiplications into only one division and one multiplication. Anyways you can probably ignore this post, I''m enjoying being in college math and I love finding progamming algorithms I can make a little quicker
"aut viam inveniam aut faciam" - I will either find a way or make one.
Actually you could optimize it further by doing this:

points[x][y][2] = sinf(x * 0.139626340178);

But what is the point? Any good optimizing compiler will do this for you, micro-optimization is bad, and it's an init function. Who cares?

[edited by - Neosmyle on December 20, 2002 12:21:32 AM]
Advertisement
Heh, yeah, d''oh I missed that.

Why optimize like that? I think it''s kind of fun. And it is computer science, after all.


"aut viam inveniam aut faciam" - I will either find a way or make one.
May we refer to Abrash, who gave us knowledge in that optimzation of something that''ll be called once is useless =D Still, it is a bit fun, I suppose ^_^
He''s right, though, that the compiler will do it for you.

I turned off all optimization on my compiler, and then ran the original algorithm through 16 million loops (as opposed to the original 2025)..

Un-compiler-optimized, the original took 1.3 seconds, my equation took .8 seconds, and Neo''s took .76 seconds.

But when I turned back full optimization, each algorithm ran at a constant .71 seconds.

Oh well


"aut viam inveniam aut faciam" - I will either find a way or make one.

This topic is closed to new replies.

Advertisement