Pay for Hesitation: Trick on iterating array concatenation
Pay for Hesitation
Ideas are Worthless Unless Acted Upon
Pages
Home
Authors
2011年1月19日 星期三
Trick on iterating array concatenation
nice trick!!
http://blog.eddie.com.tw/2011/01/18/faster-array-concatenation-in-as3/
array1.push.apply( array1, array2);
package
{
import flash.utils.getTimer;
public class Case2
{
private const TEST_ROUNDS:int = 50;
private const ARRAY_SIZE:int = 1000;
private var _bigArray1:Array;
private var _bigArray2:Array;
public function Case2()
{
trace("in Case2");
test_push_and_apply();
trace("");
test_concat();
}
private function iniArrays():void
{
_bigArray1 = [];
_bigArray2 = [];
for( var i:int = 0; i< ARRAY_SIZE; ++i ) { _bigArray1.push( i ); _bigArray2.push( i ); } } private function test_concat():void { iniArrays(); trace("== TEST Array Concat =="); var timer_start:int = getTimer(); for (var i:int = 0; i< TEST_ROUNDS; i++) { _bigArray1 = _bigArray1.concat(_bigArray2); } var timer_end:int = getTimer(); trace("the length of array1 is : " + _bigArray1.length); trace("== " + (timer_end - timer_start) + " miniseconds =="); } private function test_push_and_apply():void { iniArrays(); trace("== TEST Array Push and Apply =="); var timer_start:int = getTimer(); for (var i:int = 0; i< TEST_ROUNDS; i++) { _bigArray1.push.apply(_bigArray1, _bigArray2); } var timer_end:int = getTimer(); trace("the length of array1 is : " + _bigArray1.length); trace("== " + (timer_end - timer_start) + " miniseconds =="); } } }
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言