Created
January 26, 2010 07:34
-
-
Save alecmce/286642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package performancetests | |
{ | |
import flash.events.Event; | |
public class CapturedEventsTest | |
{ | |
private const COMPLETE:String = Event.COMPLETE; | |
public var iterations:uint = 5; | |
private var loops:uint = 100000; | |
private var simple:SimpleDispatcher; | |
private var data:DataDispatcher; | |
public function CapturedEventsTest() | |
{ | |
simple = new SimpleDispatcher(); | |
simple.addEventListener(Event.COMPLETE, onSimpleCompleteEvent); | |
simple.complete.add(onSimpleCompleteSignal); | |
data = new DataDispatcher(); | |
data.addEventListener(DataEvent.COMPLETE, onDataCompleteEvent); | |
data.complete.add(onDataCompleteSignal); | |
} | |
private function onSimpleCompleteEvent(event:Event):void {} | |
private function onSimpleCompleteSignal():void {} | |
private function onDataCompleteEvent(event:DataEvent):void {} | |
private function onDataCompleteSignal(value:int):void {} | |
public function simpleEvent():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
simple.dispatchEvent(new Event(Event.COMPLETE)); | |
} | |
public function simpleEventOptimised():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
simple.dispatchEvent(new Event(COMPLETE)); | |
} | |
public function simpleSignal():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
simple.complete.dispatch(); | |
} | |
public function dataEvent():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
data.dispatchEvent(new DataEvent(DataEvent.COMPLETE, i)); | |
} | |
public function dataEventOptimised():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
data.dispatchEvent(new DataEvent(COMPLETE, i)); | |
} | |
public function dataSignal():void | |
{ | |
for (var i:uint = 0; i < loops; i++) | |
data.complete.dispatch(i); | |
} | |
} | |
} | |
import org.osflash.signals.Signal; | |
import flash.events.Event; | |
import flash.events.EventDispatcher; | |
internal class SimpleDispatcher extends EventDispatcher | |
{ | |
public var complete:Signal; | |
public function SimpleDispatcher() | |
{ | |
complete = new Signal(); | |
} | |
} | |
internal class DataDispatcher extends EventDispatcher | |
{ | |
public var complete:Signal; | |
public function DataDispatcher() | |
{ | |
complete = new Signal(int); | |
} | |
} | |
internal class DataEvent extends Event | |
{ | |
public static const COMPLETE:String = Event.COMPLETE; | |
public var data:int; | |
public function DataEvent(type:String, data:int, bubbles:Boolean = false, cancelable:Boolean = false) | |
{ | |
this.data = data; | |
super(type, bubbles, cancelable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment