
Welcome Guest
|
#1
|
||||
|
||||
|
writing Faster Code Script - tips and advice
Hi,
I have a question about writing faster code but... let me start by saying that this is not about "best practice" or writing legible or nice looking code. What I want to do is get my code to process as quickly as possible on my machine. now... I have heard that it is better to reference functions than to write them explicitely: ex) (slower): Actionscript:
for (var mc in _array) {
_array[mc]._x = Math.sin(Math.PI*i);
}(faster): Actionscript:
var pi:Number = Math.PI;
var sinFunc = Math.sin;
for (var mc in _array) {
_array[mc]._x = sinFunc(pi*i);
}now I want to add class vs. instance to the discussion. I use the following frequently: Actionscript:
Math.PI; Math.sin; 180/Math.PI ; // (...and more) currently I have a global object called: MyObject from which all other movie clip classes extend. MyObject looks like this: Actionscript:
class MyObject extends MovieClip {
static var PI = Math.PI;
static var SIN_FUNC = Math.sin;
}and from that I have other classes inhereting as: Actionscript:
class SubObject extends MyObject {
var enterFrameCount:Number = 0;
function Move() {
_x = SIN_FUNC(enterFrameCount*PI);
enterFrameCount++;
}
}is this the fastest way to do it? does static vs non-static make a difference? What about using variables that are inherited vs declared in the child class? would it be faster in the above to rewrite as: Actionscript:
class SubObject {
//does not extend
var enterFrameCount:Number = 0;
var PI = Math.PI;
var SIN_FUNC = Math.sin;
function Move() {
_x = SIN_FUNC(enterFrameCount*PI);
}
}any concrete suggestions related to this or other ways to increase code performance would be great! I don't care about good OOP practice at this point, I will use my own discretion when deciding between "best practice" and "fastest code". The only thing I am *not* willing to do is use the tellTarget() command in place of "." sytax. Links to articles are also welcome, but I am specifically concerned about some of the AS2.0 specific issues (such as instance vs. class variables, inherited variable references, etc) ps: I already know about making variable and function names as short as possible to increase speed--even though I didn't do that in the above. Last edited by Scottae : 09-08-2005 at 03:14 PM Reason: Format with AS tags |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I want an all-flash website. Need advice and tips | cmM | Newbies |
17 | 05-05-2005 02:46 PM |

Programming Languages



