forked from: forked from: forked from: Vector index casting
♥0 |
Line 53 |
Modified 2010-11-01 23:19:57 |
MIT License
archived:2017-03-20 12:32:37
ActionScript3 source code
/**
* Copyright jozefchutka ( http://wonderfl.net/user/jozefchutka )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/wtm8
*/
// forked from marcel.klammer's forked from: forked from: Vector index casting
// forked from pleclech's forked from: Vector index casting
// forked from inspirit's Vector index casting
package {
import flash.utils.getTimer;
import flash.text.TextField;
import flash.events.*;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var _txt:TextField;
public function FlashTest() {
_txt = new TextField();
_txt.width = 300;
_txt.autoSize = 'left';
addChild(_txt);
stage.addEventListener(MouseEvent.CLICK, test);
}
public function test(e:Event = null):void
{
var n:uint = 50000000;
var i:uint;
var vec:Vector.<Number> = new Vector.<Number>(n, true);
_txt.text = '';
var t:int = getTimer();
for(i = 0; i < n; ++i)
{
vec[i+1.5-1.5] = 1.0;
}
_txt.appendText('no cast: ' + (getTimer()-t) + 'ms\n');
//
t = getTimer();
for(i = 0; i < n; ++i)
{
vec[(i+1.5-1.5)|0] = 1.0;
}
_txt.appendText('bit cast: ' + (getTimer()-t) + 'ms\n');
//
t = getTimer();
for(i = 0; i < n; ++i)
{
vec[int(i+1.5-1.5)] = 1.0;
}
_txt.appendText('int cast: ' + (getTimer()-t) + 'ms\n');
//
t = getTimer();
for(i = 0; i < n; ++i)
{
vec[uint(i+1.5-1.5)] = 1.0;
}
_txt.appendText('uint cast: ' + (getTimer()-t) + 'ms\n');
//
t = getTimer();
for(i = 0; i < n; ++i)
{
vec[i+uint(1.5-1.5)] = 1.0;
}
_txt.appendText('uint cast: ' + (getTimer()-t) + 'ms\n');
}
}
}