Created
January 26, 2010 07:33
-
-
Save alecmce/286640 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 EventsTest | |
{ | |
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 EventsTest() | |
{ | |
simple = new SimpleDispatcher(); | |
data = new DataDispatcher(); | |
} | |
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