Reputation: 12905
For e.g.
function showIt():void {
something.visible = true;
}
function init():void {
time1 = flash.utils.getTimer();
showIt();
time2 = flash.utils.getTimer();
}
<mx:st id="something" visible="false"/>
<mx:Button click="init()"/>
In the above code, I want to measure the time taken to display st on screen.
Is it enough to compute time2 - time1?
Or should I put an event handler on render?
Or some other way?
Upvotes: 0
Views: 1541
Reputation: 79268
You should try out Grant Skinner's AS3 Performance Test Harness.
Here's a simple demo of it in action (from his blog):
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
performancetests.GraphicsTests (5 iterations)
Testing different approaches for drawing.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
tare [3] 2 0.40
drawPath 242 48.40
drawPathShort 171 34.20
fullPath 182 36.40
reference 127 25.40
shortReference 129 25.80
withGraphics 1154 230.80
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
In the download he has a class called "RenderTest.as", which he describes with:
Represents a render test, which times how long it takes to draw a specified DisplayObject to a BitmapData instance.
I use it all the time, it's great.
Hope that helps, Lance
Upvotes: 2
Reputation: 9267
Using the Profiler will probably be more interesting to compare such operations.
Upvotes: 1
Reputation: 15623
you can draw it into a BitmapData to force rendering and measure the time required.
greetz
back2dos
Upvotes: 1
Reputation: 59451
time2 - time1
will just give you the time required to set the visible
property of the UIComponent
to true
- which might be just a couple of lines of code. The real rendering happens at regular intervals when the UIComponent
fires enterFrame
event. I don't know of any method to measure the time taken to render one particular component, and I don't think you can do that.
One idea that comes to mind is to listen for ENTER_FRAME
and calculate the time difference between two consecutive events (or even better: take average over, say, 100 frames) to get an estimate of the time taken for rendering the whole stage. Now repeat the experiment after removing the particular component from stage. The difference between the two timings will give you an idea of the time taken to render your component.
Upvotes: 0