Yesterday I read some oldschool articles about heavy optimization techniques from the demo-scene. One thing that has been mentioned was the use of throw. Throw slows your code down since there is an overhead for every function.
I do not want to go into detail but you can imagine that the AVM2 has to know that a function can throw. The problem is that I can not look into something like the FLASM instructions (which was possible for AS2). But the tests tell me that throw is slow! But not that slow.
It is about ~70ms at 10^6 iterations.
[as] var t0: Number;
var t1: Number;
var stop: Boolean;
stop = ( t0 && t1 );
var f0: Function = function( v: int ): int
{
if ( stop )
return 0;
return v++;
}
var f1: Function = function( v: int ): int
{
if ( stop )
throw new Error(‘The error is that throw is slow.’);
return v++;
}
var i: int;
var j: int;
for ( var k: int = 0; k < 3; k++ )
{
i = 0;
j = 0;
t0 = (new Date()).getTime();
for ( i = 0; i < 1000000; i++ )
j = f0( j );
t1 = (new Date()).getTime();
trace( 'No throw: ' + ( t1 - t0 ) + 'ms' );
i = 0;
j = 0;
t0 = (new Date()).getTime();
for ( i = 0; i < 1000000; i++ )
j = f1( j );
t1 = (new Date()).getTime();
trace( 'With throw: ' + ( t1 - t0 ) + 'ms' );
}[/as]
So what I get from this is that throw costs only a little bit of time. If you want to optimize your code hardcore you have to kick out all the throw statements. You would also not use all the possible OOP features.
I will continue using throw. Sometimes a throw is not important but in some cases it is very handy. The speed gain without throw is not that much.
Yesterday I read some oldschool articles about heavy optimization techniques from the demo-scene. One thing that has been mentioned was the use of throw. Throw slows your code down since there is an overhead for every function.
I do not want to go into detail but you can imagine that the AVM2 has to know that a function can throw. The problem is that I can not look into something like the FLASM instructions (which was possible for AS2). But the tests tell me that throw is slow! But not that slow.
It is about ~70ms at 10^6 iterations.
[as] var t0: Number;
var t1: Number;
var stop: Boolean;
stop = ( t0 && t1 );
var f0: Function = function( v: int ): int
{
if ( stop )
return 0;
return v++;
}
var f1: Function = function( v: int ): int
{
if ( stop )
throw new Error('The error is that throw is slow.');
return v++;
}
var i: int;
var j: int;
for ( var k: int = 0; k < 3; k++ )
{
i = 0;
j = 0
Published on
Apr 24, 2006 in
misc.
After 13 years I had my last day in school on last friday. It was a very sentimental moment when I stood with all my friends together and celebrated our last day at school. A strange feeling when there is nothing to do instead of writing the exams and waiting for the next term to begin studying.
As I wrote some weeks ago I also did some extra exams in object recognition. I think the paper I had to wrote is very nice but I am not sure if I may publish it here since my teacher and professor have not looked over it. The whole thing is about object recognition with motion detection. I used a lot of filters like Dilation, Erosion, Closing, Convolution, Retinex and others. I also did some tests in Flash. You can find them in the directory /as3/ip/. But I have to say that most of them are not very up to date.
I also finished a project for school which was about motion-detection and response. Therefore I developed an eyetoy-like game. It is fun to play around with Flash and a webcam.
I will have to update the project for Flex Builder 2 Beta 2 to release it here. But now I have holidays and time to learn for my final exams. And of course enough time to start with a lot of funny experiments :o)
After 13 years I had my last day in school on last friday. It was a very sentimental moment when I stood with all my friends together and celebrated our last day at school. A strange feeling when there is nothing to do instead of writing the exams and waiting for the next term to begin studying.
As I wrote some weeks ago I also did some extra exams in object recognition. I think the paper I had to wrote is very nice but I am not sure if I may publish it here since my teacher and professor have not looked over it. The whole thing is about object recognition with motion detection. I used a lot of filters like Dilation, Erosion, Closing, Convolution, Retinex and others. I also did some tests in Flash. You can find them in the directory /as3/ip/. But I have to say that most of them are not very up to date.
I also finished a project for school which was about motion-detection and response. Therefore I developed an eyetoy-like game. It is fun to play around with Flash and a webcam.
I will have to update the pr