flash on 2011-4-6
♥0 |
Line 56 |
Modified 2011-04-06 10:12:56 |
MIT License
archived:2017-03-20 11:24:02
ActionScript3 source code
/**
* Copyright John_Blackburne ( http://wonderfl.net/user/John_Blackburne )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jY9M
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.getTimer;
public class FlashTest extends Sprite {
var tf1:TextField, tf2:TextField;
var tf3:TextField, tf4:TextField;
public function FlashTest() {
// write as3 code here..
tf1 = new TextField();
tf2 = new TextField();
tf3 = new TextField();
tf4 = new TextField();
tf1.x = tf2.x = tf3.x = tf4.x = 100;
tf1.y = 100;
tf2.y = 120;
tf3.y = 140;
tf4.y = 160;
tf1.text = tf2.text = tf3.text = tf4.text = "Starting...";
addChild(tf1);
addChild(tf2);
addChild(tf3);
addChild(tf4);
var x:Number, y:Number, z:Number, w:Number;
var i:int, iLoops:int = 10000000, t:Number;
x = 0; y = 20; z = 10;
w = 0;
// test 1: function call
t = getTimer();
for (i = 0; i < iLoops; i++) {
w = clamp(z, x, y);
}
tf1.text = String(getTimer() - t);
w = 0;
// test 2: inline calculations
t = getTimer();
for (i = 0; i < iLoops; i++) {
w = z < x ? x : z > y ? y : z;
}
tf2.text = String(getTimer() - t);
w = 0;
// test 3: function call
t = getTimer();
for (i = 0; i < iLoops; i++) {
w += clamp(z, x, y);
}
tf3.text = String(getTimer() - t);
w = 0;
// test 4: inline calculations
t = getTimer();
for (i = 0; i < iLoops; i++) {
w += z < x ? x : z > y ? y : z;
}
tf4.text = String(getTimer() - t);
}
function clamp(x:Number, min:Number, max:Number):Number
{
return x<min?min:x>max?max:x;
}
}
}