Performance test == , === , ()
Performance comparison between
if(a == null) {
}
if(a === null) {
}
if(a) {
}
♥0 |
Line 49 |
Modified 2012-02-23 03:44:49 |
MIT License
archived:2017-03-20 08:26:37
ActionScript3 source code
/**
* Copyright leichtgewicht ( http://wonderfl.net/user/leichtgewicht )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/w4Ai
*/
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.getTimer;
import flash.utils.setTimeout;
public class Main extends Sprite
{
private var _t: TextField = new TextField();
public function Main() {
addChild( _t );
_t.width = 200;
_t.height = 200;
setTimeout(start, 10);
}
public function start():void {
var c: int = 100000000;
var i: int;
var a: MyType;
for( i=0;i<c;++i) {
a = null;
}
var t: Number;
t = getTimer();
for( i = 0; i<c; ++i) {
if( a == null ) {}
}
t = getTimer()-t;
trace("==", t);
t = getTimer();
for( i = 0; i<c; ++i) {
if( a === null ) {}
}
t = getTimer()-t;
trace("===",t);
t = getTimer();
for( i = 0; i<c; ++i) {
if( a ) {}
}
t = getTimer()-t;
trace("()",t);
}
protected function trace(msg:String, no:int):void {
_t.appendText(msg+": "+no+" ms\n");
}
}
}
class MyType {
}