[Stardust] Paritcle Collection Performance Test
http://code.google.com/p/stardust-particle-engine/source/browse/trunk/tests/ParitcleCollectionParformanceTest/src/idv/cjcat/stardust/tests/ParitcleCollectionParformanceTest.as
/**
* Copyright paq ( http://wonderfl.net/user/paq )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7TyE
*/
// http://code.google.com/p/stardust-particle-engine/source/browse/trunk/tests/ParitcleCollectionParformanceTest/src/idv/cjcat/stardust/tests/ParitcleCollectionParformanceTest.as
package
{
import com.bit101.components.Label;
import com.bit101.components.PushButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.getTimer;
import idv.cjcat.stardust.common.particles.ParticleArray;
import idv.cjcat.stardust.common.particles.ParticleCollection;
import idv.cjcat.stardust.common.particles.ParticleFastArray;
import idv.cjcat.stardust.common.particles.ParticleIterator;
import idv.cjcat.stardust.common.particles.ParticleList;
import idv.cjcat.stardust.twoD.particles.Particle2D;
[SWF(backgroundColor="#FFFFFF", width=465, height=465, frameRate=60)]
public class Main extends Sprite
{
public function Main()
{
large(new Label(this, 10, 0, "Traverse"));
new PushButton(this, 10, 40, "Array", traverse(ParticleArray));
new PushButton(this, 10, 70, "Linked List", traverse(ParticleList));
new PushButton(this, 10, 100, "Fast Array", traverse(ParticleFastArray));
large(new Label(this, 120, 0, "Splice"));
new PushButton(this, 120, 40, "Array", splice(ParticleArray));
new PushButton(this, 120, 70, "Linked List", splice(ParticleList));
new PushButton(this, 120, 100, "Fast Array", splice(ParticleFastArray));
large(new Label(this, 230, 0, "Sort"));
new PushButton(this, 230, 40, "Array", sort(ParticleArray));
new PushButton(this, 230, 70, "Linked List", sort(ParticleList));
new PushButton(this, 230, 100, "Fast Array", sort(ParticleFastArray));
label = new Label(this, 10, 130);
}
private const COUNT:int = 50000;
private var label:Label;
private function large(lbl:Label):void
{
lbl.scaleX = lbl.scaleY = 2;
}
private function traverse(cls:Class):Function
{
return function(e:Event):void {
var pc:ParticleCollection = new cls();
var i:int = 0;
for (i = 0; i < COUNT; i++) pc.add(new Particle2D());
var iter:ParticleIterator = pc.getIterator();
var t:int = getTimer();
while (iter.particle) iter.next();
label.text = e.target.label + " :" + (getTimer() - t) + "ms";
}
}
private function splice(cls:Class):Function
{
return function(e:Event):void {
var pc:ParticleCollection = new cls();
var i:int = 0;
for (i = 0; i < COUNT; i++) pc.add(new Particle2D());
var iter:ParticleIterator = pc.getIterator();
var t:int = getTimer();
while (iter.particle) iter.remove();
label.text = e.target.label + " :" + (getTimer() - t) + "ms";
}
}
private function sort(cls:Class):Function
{
return function(e:Event):void {
var pc:ParticleCollection = new cls();
var i:int = 0;
for (i = 0; i < COUNT; i++) pc.add(new Particle2D());
var iter:ParticleIterator = pc.getIterator();
var t:int = getTimer();
pc.sort();
label.text = e.target.label + " :" + (getTimer() - t) + "ms";
}
}
}
}