Comparison of VaR read/write and function read/write, get/set read/write Efficiency

Source: Internet
Author: User

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;
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.