Vector.<String>のlengthを変えて使い回し
forked from new Vector.<String>(500) のがーべじコレクション? (diff: 4)
Vector.のlengthを変えて使い回し
ActionScript3 source code
/**
* Copyright yasurageruheya ( http://wonderfl.net/user/yasurageruheya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rYFB
*/
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.system.System;
import flash.text.TextField;
import flash.utils.ByteArray;
public class FlashTest extends Sprite {
public const LOOP:int = 1000;
public const txt:TextField = new TextField();
public var tests:Vector.<Tester> = new Vector.<Tester>();
public var freeMemory:int;
public var gcCount10byte:int = 0;
public var gcCount100byte:int = 0;
public var gcCount1KB:int = 0;
public var gcCount10KB:int = 0;
public var gcCount100KB:int = 0
public var gcCount1MB:int = 0;
public var gcCount10MB:int = 0;
public var gcCount100MB:int = 0;
public var gcCount:int = 0;
public var totalFrames:Number = 1;
public function FlashTest() {
var vec:Vector.<String> = new Vector.<String>();
var count:int = 0;
var strings:Vector.<String> = Vector.<String>(["w","q","u","C","p","t","m","r","M","r","j","a","J","J","L","U","p","r","T","z","c","l","V","j","Q","A","e","T","Z","m","R","Y","x","m","o","o","y","w","k","g","m","A","G","s","n","i","V","Q","G","m","q","p","a","t","I","q","k","k","d","z","K","g","o","w","X","M","E","F","u","e","H","g","r","Z","d","C","U","n","h","J","D","P","H","b","C","u","j","E","l","P","k","t","O","C","F","g","c","p","z","T","r","i","F","x","Y","V","a","j","D","O","U","b","O","z","S","O","L","w","Z","h","L","X","R","y","B","p","J","f","T","d","f","r","s","k","q","o","W","f","f","I","e","p","A","V","P","Z","B","v","B","Q","m","O","H","j","B","V","W","d","j","r","h","f","H","J","x","a","Y","K","A","t","c","I","d","U","H","m","t","B","E","D","g","z","J","q","D","d","y","D","t","r","c","O","q","V","h","Y","U","t","M","h","L","t","z","D","W","s","H","I","T","n","V","K","Z","k","d","q","b","B","n","n","k","z","w","d","n","r","B","h","P","r","q","R","M","w","P","x","j","e","W","C","r","x","r","Q","I","w","D","K","c","D","k","h","e","k","X","G","f","Z","g","G","p","g","B","R","f","C","i","g","b","J","N","G","v","w","p","y","l","D","a","N","w","T","l","C","i","g","r","V","M","F","q","z","H","B","r","f","w","D","z","W","W","C","K","V","i","m","R","A","A","Z","B","h","A","T","R","K","E","L","u","B","B","t","q","J","m","u","u","n","p","U","x","m","E","a","a","v","n","e","v","e","P","C","a","E","X","f","c","v","O","H","h","f","s","p","M","i","Y","t","r","u","I","a","E","V","F","h","S","x","A","x","i","C","G","o","H","Y","V","j","s","n","L","w","J","X","r","r","T","e","k","U","d","S","e","F","b","i","g","Y","U","L","Z","Z","D","F","I","U","L","z","b","t","x","D","t","c","y","d","S","k","O","V","S","y","z","F","q","o","n","r","O","m","o","w","P","z","L","M","v","B","N","i","j","E","C","V","P","S","M","e","c","f","H","y","H","c","o","t","d","i","j","B","n","e","W","C","L","R","i","h","Q","C","z","t","b","I","g","T","E","Q","Z","I","Z","o","j","z","Z","z","N","C","C","U","B","P","y","a","N","z","j","v","t","e","B","O","O","H","r"]);
/*
tests[tests.length] = new Tester("プールが空の状態 fromPool : ", function():void
{
var i:int = LOOP;
while (i--)
{
vec[i] = PoolLoader.fromPool();
}
});
tests[tests.length] = new Tester("プーリング toPool : ", function():void
{
var i:int = LOOP;
while (i--)
{
PoolLoader.toPool(vec[i]);
}
});
vec = new Vector.<Loader>(LOOP);
tests[tests.length] = new Tester("プールから取り出す fromPool : ", function():void
{
var i:int = LOOP;
while (i--)
{
vec[i] = PoolLoader.fromPool();
}
});
/*/
tests[tests.length] = new Tester("vec.length=500 : ", function():void
{
var i:int = LOOP;
var j:int;
while (i--)
{
vec.length = 0;
vec.length = 500;
j = vec.length;
while (j--)
{
vec[j] = strings[j];
}
}
});
//*/
tests.reverse();
txt.width = 500;
txt.height = 500;
addChild(txt);
freeMemory = System.freeMemory;
// write as3 code here..
addEventListener(Event.ENTER_FRAME, test);
}
private function test(e:Event):void
{
var str:String = "";
var i:int = tests.length;
while (i--)
{
str += tests[i].start();
}
if (tests.length > 1)
{
str += "プーリングと取り出しの合計 : " + (tests[0].timeAverage + tests[1].timeAverage) + " ms.\n";
}
str += "memory : total " + System.totalMemory + " / private " + System.privateMemory + "\n";
const currentFreeMemory:Number = System.freeMemory;
if (freeMemory < currentFreeMemory)
{
gcCount++;
const gcMemory:Number = currentFreeMemory - freeMemory;
if (gcMemory > 100000000)
{
gcCount100MB++;
}
else if (gcMemory > 10000000)
{
gcCount10MB++;
}
else if (gcMemory > 1000000)
{
gcCount1MB++;
}
else if (gcMemory > 100000)
{
gcCount100KB++;
}
else if (gcMemory > 10000)
{
gcCount10KB++;
}
else if (gcMemory > 1000)
{
gcCount1KB++;
}
else if (gcMemory > 100)
{
gcCount100byte++;
}
else if (gcMemory > 10)
{
gcCount10byte++;
}
}
freeMemory = System.freeMemory;
str += "\n100MB\tGC発生回数?\t: " + gcCount100MB;
str += "\n10MB\t\tGC発生回数?\t: " + gcCount10MB;
str += "\n1MB\t\tGC発生回数?\t: " + gcCount1MB;
str += "\n100KB\t\tGC発生回数?\t: " + gcCount100KB;
str += "\n10KB\t\tGC発生回数?\t: " + gcCount10KB;
str += "\n1KB\t\tGC発生回数?\t: " + gcCount1KB;
str += "\n100byte\tGC発生回数?\t: " + gcCount100byte;
str += "\n10byte\t\tGC発生回数?\t: " + gcCount10byte;
str += "\n\t\t\tGC発生回数?\t: " + gcCount;
str += "\n\t\t\tGC発生率?\t: " + ((gcCount / (totalFrames++)) * 100) + "%";
txt.text = str;
}
}
}
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.geom.Rectangle;
import flash.system.System;
import flash.utils.ByteArray;
import flash.utils.Dictionary;
import flash.utils.getTimer;
class Tester
{
public var time:Number = 0;
public var name:String;
public var test:Function;
public var count:Number = 1;
[Inline]
final public function start():String
{
const startTime:int = getTimer();
test();
time += getTimer() - startTime;
return name + (time / (count++)) + " ms.\n";
}
[Inline]
final public function get message():String
{
return name + (time / count) + " ms.\n";
}
[Inline]
final public function get timeAverage():Number
{
return time / count;
}
public function Tester(name:String, test:Function)
{
this.name = name;
this.test = test;
}
}
