HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Precision vs. efficiency, or just silly?

10-10-2008, 05:35 PM#1
the-thingy
This may seem like a very trivial question, but:

With regard to efficiency, would it be viable to do
Collapse JASS:
function InitFunc takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 360
  set cos[i] = Cos (I2R (i) * bj_DEGTORAD)
  set sin[i] = Sin (I2R (i) * bj_DEGTORAD)
  set i = i + 1
endloop
endfunction

...

function SomethingThatRequiresCos takes nothing returns nothing
local real x = sourceX + cos[I2R (angle * bj_RADTODEG)] * offset
//etc
endfunction
and if so, would the loss of precise be justifiable by any increase in efficiency, rather than calculating Cos/Sin values everytime a trigger runs (and storing those pre-calculated cos/sin values in a struct for passing to a timer, or whatever)

Or is this just something silly, that won't really make a difference. Just curious (haven't really much intention of using it, just thought it'd be interesting to find out)
10-10-2008, 05:49 PM#2
moyack
You'll gain micro seconds in calculation time but you lost precision in a huge way... I think this is not a good deal.

Sin and Cos function are very efficient, so my opinion is that this is not practical.
10-10-2008, 06:03 PM#3
Troll-Brain
I already tried and the result is the same or a bit slower, so let's say it's useless.
(I have not keep any benchmark results)
10-10-2008, 07:00 PM#4
the-thingy
Quote:
Originally Posted by moyack
You'll gain micro seconds in calculation time but you lost precision in a huge way... I think this is not a good deal.

Sin and Cos function are very efficient, so my opinion is that this is not practical.
So, by comparison to pre-calculating the sin/cos before passing it to timer, assuming it was in relation to a spell, it'd be a total waste of time? Hmmm... didn't expect the precision to be off in a huge way - with respect to this diagram, it doesn't seem that way (even though I'm not an expert on trigonometry)


well, thanks for clearing that up for me (now I won't get any mad notions of using it )
10-10-2008, 11:39 PM#5
Captain Griffen
Sin/Cos are faster than empty function calls. I'm fairly sure Blizzard already uses a lookup table of some kind. They are lightning fast, don't worry about them.
10-11-2008, 10:12 AM#6
Toadcop
Quote:
Sin/Cos are faster than empty function calls
lol ...
10-11-2008, 10:26 AM#7
the-thingy
Hmmm, I was informed that Sin/Cos were very math-intensive (and, from that, assumed they would be slower and/or prone to reducing performance).
10-11-2008, 11:11 AM#8
ToukoAozaki
Quote:
Originally Posted by the-thingy
Hmmm, I was informed that Sin/Cos were very math-intensive (and, from that, assumed they would be slower and/or prone to reducing performance).

I thought that as a normal programmer's approach, but it seems that blizz already knew the problem and made a workaround. Those trignometric natives are optimized, so use them freely.