| 10-10-2008, 05:35 PM | #1 |
This may seem like a very trivial question, but: With regard to efficiency, would it be viable to do 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 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 |
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 |
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 | |
Quote:
![]() 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 |
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 | |
Quote:
|
| 10-11-2008, 10:26 AM | #7 |
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 | |
Quote:
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. |
