|
#1
|
|||||||||
|
|||||||||
|
Hey there, jamu here.
For all you Flash Devs out there, today I'm going to show you how to check if your functions can be optimized, and how optimized they can get. Here's a little code snippet that you can copy and paste into Flash. It's AS3, of course, so you AS2 users will have to transcribe the code back into prehistoric times! Code:
var lo:int = 1024; // The amount of times you want to test each function
var o:int = getTimer(); // getTimer returns the time since the Flash was activated in milliseconds
for (var j=0; j<lo; ++j) {
// Paste or Write a function/command here
}
trace(getTimer()-o); // Returns how long it took to complete the function in milliseconds
o = getTimer();
for (j=0; j<lo; ++j) {
// Paste or Write a function/command to compare here
}
trace(getTimer()-o);
// o = getTimer(); // <- Uncomment and copy+paste the above function to compare more than 2 functions
Some things that you might be interested to know; fillRect() is an incredibly fast function! It takes on ~900ms to run it one million times! However, to call the function, you need a rectangle and a color. If you use it as so; fillRect(new Rectangle(x,y,w,h), 0xFFFFFFFF); It takes ~900ms to complete, because it creates a new rectangle every cycle, however if you define a rectangle that you're going to use often, you can nearly halve the speed! When run 1,000,000 times, creating a new rectangle took 826, and using a pre-defined rectangle took only 396! Use it wisely, as it can really affect how stable your FPS is when you make crazy games like I do!
__________________
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
| Please support this website by checking out our sponsors! |