Comparison of VaR read/write and function read/write, get/set read/write Efficiency
VaR is about 4 times faster than function,
GET/set is similar to function
95
VaR read: 567
VaR write: 563
[SWF] D: \ flexproject \ testspeed \ bin-Debug \ testspeed.swf-2,091 bytes after decompression
Function read: 1860
Function write: 2117
GET/set read: 1927
GET/set write: 2119
// Test code
Package {
Import flash. display. Sprite;
Import flash. utils. gettimer;
Public class testspeed extends Sprite
{
Public Function testspeed ()
{
VaR aone: speedtest = new speedtest ();
VaR MAX: Int = 5000000; // 50000000
VaR old: Int = gettimer ();
For (var I: Int = 0; I <Max; I + = 1 ){
}
// Var fortime: Int = gettimer ()-old;
Old = gettimer ();
// Trace (fortime );
Trace (old );
//
VaR T: Int = 0;
For (I = 0; I <Max; I + = 1 ){
T = aone. testvar;
}
Trace ("Var read:", gettimer ()-old); //-fortime );
Old = gettimer ();
For (I = 0; I <Max; I + = 1 ){
AOne. testvar = T;
}
Trace ("Var write:", gettimer ()-old); //-fortime );
//
Old = gettimer ();
//
For (I = 0; I <Max; I + = 1 ){
T = aone. testfunctionget ();
}
Trace ("function read:", gettimer ()-old); //-fortime );
Old = gettimer ();
For (I = 0; I <Max; I + = 1 ){
AOne. testfunctionset (t );
}
Trace ("function write:", gettimer ()-old); //-fortime );
//
Old = gettimer ();
//
For (I = 0; I <Max; I + = 1 ){
T = aone. testget;
}
Trace ("Get/set read:", gettimer ()-old); //-fortime );
Old = gettimer ();
For (I = 0; I <Max; I + = 1 ){
AOne. testset = T;
}
Trace ("Get/set write:", gettimer ()-old); //-fortime );
}
}
}
//
Package {
Public class speedtest {
Public Function speedtest (){}
Public var testvar: Int = 0;
Private VaR _ function: Int = 0;
Private VaR _ GetSet: Int = 0;
Public Function testfunctionget (): int {
Return this. _ function;
}
Public Function testfunctionset (I: INT): void {
This. _ FUNCTION = I;
}
Public Function set testset (I: INT): void {
This. _ GetSet = I;
}
Public Function get testget (): int {
Return this. _ GetSet;
}
}
}