Thread: tiles[x,y] ?
View Single Post
  #28  
Old 12-09-2005, 09:07 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
For the record, I went ahead and benchmarked this crap because you are all to lazy.

For expressions of numbers versus a single number out of 26 runs:
13 times the expression was faster
13 times the single number was faster

For expressions/single numbers (if you don't understand why I now group these, go away, you are stupid) versus a constant variable look-up in 26 runs:
1 time the constant look-up was faster
25 times the expression was faster

Now we must figure out the meaning of these results:
First, I ran these through 10 consecutive 10000 iteration loops, meaning this is a very extreme case. Second, the difference in timing was thus;
For the first test:
-average difference: .04 seconds
-smallest difference: .01 seconds
-largest difference: .1 seconds
For the second:
-average difference: .2 seconds
-smallest difference: .017 seconds
-largest difference: .37 seconds

None of these numbers are substantial given the context. So it is apparent that giving Graal an expression versus a computed expression makes no difference (as it is bytecoded, I am told by several very reputable sources). It is also true that while giving an expression is more efficient versus using a constant concerning CPU time. However, as Fox has already clarified, using a constant for recurring data is very beneficial to saving programmer time. If you do not understand this, you require more experience. When you use expressions only, and you need to change all instances of that expression in a complex code, then you will be thankful to have used a constant. This is governed by the inevitability that you will miss some instances and require debugging time just to change recurring data.

To summarise, using number expressions will benefit you by removing the abstractness of magic numbers(granted you want this). Using a constant to store recurring data in code will benefit you in programmer lookup and debugging time when you need to change that data.
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial

Last edited by Dach; 12-09-2005 at 09:32 PM.. Reason: Now with non-estimated stats!
Reply With Quote