Play free games online!


Go Back   The Game Homepage Forums > Development > Flash Development

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-29-2009, 01:19 PM
noobjam's Avatar
Flash Developer
Recycle Bin
Better than 48.05% Better than 48.05% Better than 48.05%
 
Join Date: Jul 2007
Posts: 435
noobjam has a spectacular aura aboutnoobjam has a spectacular aura aboutnoobjam has a spectacular aura aboutnoobjam has a spectacular aura about
Default Optimization Snippet

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
It really helps when it comes down to really critical aspects of your game.

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!
__________________


Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Please support this website by checking out our sponsors!

All times are GMT. The time now is 06:40 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2007, Crawlability, Inc.