Events and Signals – Performance Tests

The new as3signals library devised by Robert Penner offers a replacement to the native AS3 event model. One benefit is that signals are more lightweight, and therefore faster. Grant Skinner’s Performance Harness is a widely accepted library for comparing the speeds of code execution.

I found the following results on Mac OS X, Flash Player 10.0.42.34, with a release build.

When an event (signal) is dispatched but nothing is listening for it:

A graph indicating that as3signals events dispatch roughly 5 times faster than native as3 events.

When an event (signal) is dispatched and handled by one method listener:

A graph indicating that as3signals signals are dispatched and captured at twice the speed of native as3 events.

The source code for my test methods follows:

If you browse these tests, you will notice that more tests were run than I have displayed above. The graphs above reference results from running the dataEventOptimised and dataSignal methods in each context.

These tests are not scientific. No attempt has been to control for player version, computer version, computer specifications, so on and so forth. You are invited to download and run these tests for yourself. If you do, remember that testing on a release build not a debug build is appropriate, and then please post your results as a comment, particularly if your results differ from my own.

Updates

For a comparison with good old fashioned callbacks, please put on your sarcasm snorkel and visit va.lent.in’s follow up post.

From the as3signals Google Group there was a suggestion that the Flash Player 10.1 might produce different results. Here are my results; they appear to corroborate the earlier results:

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
performancetests.EventsTest (5 iterations)
Player version: MAC 10,1,51,66 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
dataEvent                                                  2344   468.80
dataEventOptimised                                         2270   454.00
dataSignal                                                  313    62.60
simpleEvent                                                2755   551.00
simpleEventOptimised                                       2285   457.00
simpleSignal                                                174    34.80
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
performancetests.CapturedEventsTest (5 iterations)
Player version: MAC 10,1,51,66 (regular)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
dataEvent                                                  2708   541.60
dataEventOptimised                                         2703   540.60
dataSignal                                                 1182   236.40
simpleEvent                                                2724   544.80
simpleEventOptimised                                       2717   543.40
simpleSignal                                               1042   208.40
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

29 thoughts on “Events and Signals – Performance Tests

  1. Good stuff, saves me having to write these tests :)

    Out of interest, did you run any memory tests? I have a vague feeling that signals should be significantly less memory intensive than events, due to no event object creation, cloning and so on. If you haven’t, I’ll have a fiddle with it tonight.

  2. Good stuff, saves me having to write these tests :)

    Out of interest, did you run any memory tests? I have a vague feeling that signals should be significantly less memory intensive than events, due to no event object creation, cloning and so on. If you haven't, I'll have a fiddle with it tonight.

  3. You beat me to it! I was going to do a post really soon on as3signals since I’ve been hearing about them being used more recently. Perhaps I still will…

  4. They're faster, more explicit and just-as-decoupled for all practical purposes. What is there not to like about Rob Penner's Signals!?

  5. Yes, I have seen a smaller memory footprint using as3signals, in

    http://alecmce.com/as3/replacing-enter_frame-te….

    I doubt the memory difference is particularly significant though, since one good bitmap would wipe it out. More the point is that the native events must be working the GC much harder. I guess that means events cause a performance hit at both ends of the racetrack, compared to signals.

  6. You beat me to it! I was going to do a post really soon on as3signals since I've been hearing about them being used more recently. Perhaps I still will…

  7. FYI, I have just run the same tests through the latest Flash Player 10.1 beta on Mac. The results are corroborated (in order to format the results better, I’ve put them in the main post, above!)

  8. That is brilliant.

    I have been waiting for someone to do these tests (Eh! old excuse, been too busy myself :)) as the first time I heard about AS3 Signals, I have been curious if it is better than the native Events performance-wise.

    So, thanks a bunch for posting your results.

    - Tahir.

  9. That is brilliant.

    I have been waiting for someone to do these tests (Eh! old excuse, been too busy myself :)) as the first time I heard about AS3 Signals, I have been curious if it is better than the native Events performance-wise.

    So, thanks a bunch for posting your results.

    - Tahir.

  10. This test is not accurate ~~ 
    signal is more slow in add and remove than flash event. 
    This is my test http://www.cnblogs.com/pelephone/archive/2012/03/23/as3-signal-test.html

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>