View Full Version : Speed in FMX04 and Strict Typing
λ
September 12th, 2003, 06:30 PM
heh, well, I was really bored, so I decided to run a few tests on the differences in speed in FMX04 between a strictly typed variable and a non-strictly typed variable... the differences were amazing.
I used these two pieces of code:
for(var num:Number = 0;num<50000;num++){
56+51;
21+23;
53+21;
if(num == 4999){
var totalTimeDefined = getTimer();
}
}
for(var num2 = 0;num2<50000;num2++){
56+51;
21+23;
53+21;
if(num2== 4999){
var totalTimeNotDefined = getTimer();
}
}
trace(totalTimeDefined);
trace(totalTimeNotDefined-totalTimeDefined);
The output varied between 200 and 170 and 900 to 1100 on my P3 700. I'm sure the difference would get bigger and bigger as the iterations got bigger, but don't quote me on that.
I just thought some of you might find this interesting.
The moral of the story is: always use strictly typed variables when you can in 04 :)
Eric Jr.
September 12th, 2003, 06:38 PM
Yeah I know, already did some very complex tests with combinations of strict data typing, arrays in classes, objects in arrays...
The Flash 7 player seems to be 30% (average) faster then the Flash 6 player. But at some points even 86% faster :)
Your script resulted this:
45, 225
on my PC
senocular
September 12th, 2003, 06:43 PM
I dont know how accurate that is ;) it should be about the same
btw when I say I dont know, I mean I know its not :beam:
Eric Jr.
September 12th, 2003, 06:57 PM
I tracked one of the PM's ive sent you Sen, it seems like you didn't read it yet ...
senocular
September 12th, 2003, 06:59 PM
Originally posted by Eric Jr.
I tracked one of the PM's ive sent you Sen, it seems like you didn't read it yet ...
:!: ooo thanks, sometimes the pm alert seems to get by me.
senocular
September 13th, 2003, 12:05 AM
well since no one brought it up, heres the deal.
1) biggest miscalculation is the check for 4999. You're looping 50000 not 5000, so the 4999 should be 49999. Thats about 45000 loops extra you're calling between totalTimeDefined and totalTimeNotDefined. That does some hurtin for the non-strict calcs.
2) Though minor, you are using a longer itteration variable for the second loop. Thats a 33% longer variable name that will take some toll on Flash as it parses it for 50000 loops.
3) The constant additions thing is fairly futile. Flash pre-process constant calculations on export for optimization. Thats about as useful as saying 107; 44; and 74; which is pretty pointless. The increments of the looping alone is all you really need.
4) getTimer() gets the time from when the movie was started. You kind of compensate that with the second trace subtracting the totalTimeDefined from totalTimeNotDefined, but there are other things not accounted for in that time such as movie load/initialization which takes a few milliseconds after getTimer kicks in and other things like loop setup and whatnot. It'd be best if you encased the loops in the getTimer() calcs restricting the time solely to the calculations of that loop.
Here's an example giving 15 instances of loops through 50000.
max = 50000;
frames = 0;
t = 0;
this.onEnterFrame = function(){
t = getTimer();
for(var num1:Number = 0; num1<=max; num1++){}
t = getTimer()-t;
trace("Strict: "+t);
t = getTimer();
for(var num2 = 0; num2<=max; num2++){}
t = getTimer()-t;
trace("Non-strict: "+t);
if (frames++ >= 15) delete this.onEnterFrame;
};
Times I got on my work computer were:
Strict: 334
Non-strict: 329
Strict: 324
Non-strict: 322
Strict: 322
Non-strict: 328
Strict: 319
Non-strict: 322
Strict: 321
Non-strict: 319
Strict: 317
Non-strict: 318
Strict: 317
Non-strict: 315
Strict: 317
Non-strict: 318
Strict: 319
Non-strict: 316
Strict: 316
Non-strict: 316
Strict: 317
Non-strict: 317
Strict: 317
Non-strict: 318
Strict: 320
Non-strict: 318
Strict: 322
Non-strict: 318
Strict: 318
Non-strict: 316
Strict: 317
Non-strict: 322
As you can see the results are pretty even. Sometimes the strict wins, others the non-strict, but its subtle enough to see that its about the same.
All strict datatyping does for FMX04 is allow for better error control in compiling. Flash is then able to kick out errors if your Number variables are trying to be used as Objects. Otherwise, and this is unlike many other languages, strict datatyping offers no advantages in speed.
ahmed
September 13th, 2003, 12:16 AM
Originally posted by senocular
All strict datatyping does for FMX04 is allow for better error control in compiling. Flash is then able to kick out errors if your Number variables are trying to be used as Objects. Otherwise, and this is unlike many other languages, strict datatyping offers no advantages in speed. ditto ;)
madgett
April 3rd, 2005, 01:05 AM
Senocular I think it's time to upgrade your cpu :)
AMD 4000+ Benchmarks...lol, lets get some other CPUs, how bout some intels
Strict: 56
Non-strict: 56
Strict: 55
Non-strict: 55
Strict: 52
Non-strict: 56
Strict: 54
Non-strict: 51
Strict: 52
Non-strict: 52
Strict: 55
Non-strict: 54
Strict: 53
Non-strict: 55
Strict: 52
Non-strict: 54
Strict: 53
Non-strict: 53
Strict: 55
Non-strict: 56
Strict: 54
Non-strict: 54
Strict: 53
Non-strict: 54
Strict: 55
Non-strict: 53
Strict: 55
Non-strict: 55
Strict: 53
Non-strict: 54
Strict: 53
Non-strict: 54
ahmed
April 3rd, 2005, 01:06 AM
How did you manage to generate this? :)
senocular
April 3rd, 2005, 07:27 AM
Senocular I think it's time to upgrade your cpu :)
AMD 4000+ Benchmarks...lol, lets get some other CPUs, how bout some intels
Well that was 2 years ago and using a much slower Flash Player 6.
mpelland
April 3rd, 2005, 09:50 AM
Total Time Defined: 1096
Total Time Not Defined: 1155
Difference is: 59
Total Time Defined: 4976
Total Time Not Defined: 5034
Difference is: 58
Total Time Defined: 7031
Total Time Not Defined: 7089
Difference is: 58
Total Time Defined: 8271
Total Time Not Defined: 8329
Difference is: 58
ran it through a couple of times (as you can see). I would say that even though its a very minute difference, I would say when possible, use strictly defined variables.
just so you know, for my tests i changed one thing in the code... I made var totalTimeDefined:Number = getTimer(); in the first loop.. not the :Number. I figured 'why not stay totally strict.
senocular
April 3rd, 2005, 09:56 AM
just so everyone knows, and I dont know if this was mentioned yet (I dont feel like re-reading the thread), all AS typing is stripped when a swf is compiled. Typing is for compile-time error checking only. Once the swf has been published and saved, it is no different than a swf that had been compiled without variable typing.
madgett
April 3rd, 2005, 01:12 PM
Well that was 2 years ago and using a much slower Flash Player 6.
I'm just pulling your leg :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.