AlecMcE.com

Coding on the Flash Platform

Events and Signals – Performance Tests

View Comments

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
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Written by alec

January 26th, 2010 at 8:20 am

Posted in as3,performance

Tagged with

View Comments to 'Events and Signals – Performance Tests'

Subscribe to comments with RSS or TrackBack to '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.

    mnem

    26 Jan 10 at 1:15 pm

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

    troygilbert

    26 Jan 10 at 4:23 pm

  3. 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.

    alecmce

    26 Jan 10 at 4:46 pm

  4. Great Alex! I haven't used Signals yet, but I starting from tomorrow :)

    og2t

    26 Jan 10 at 5:41 pm

  5. 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…

    jacksondunstan

    26 Jan 10 at 7:54 pm

  6. 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!)

    alecmce

    27 Jan 10 at 5:45 am

  7. 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.

    TahirAhmed

    27 Jan 10 at 5:46 am

  8. [...] há por aí comparações impressionantes de desempenho, mas, acima de tudo, a vantagem é de uma implementação mais clara e simples, [...]

  9. [...] found that these screencasts are a great way to get a grasp on an idea. There has also been some testing to show that Signals can actually be quicker that Events. This could appeal to you if you are [...]

  10. I optimized Signal dispatch() by moving the listeners array clone to add() and remove(). It’s about twice as fast as before on Windows, when sending to one listener. Here's the commit:
    http://github.com/robertpenner/as3-signals/comm...

    robpenner

    10 Feb 10 at 4:44 am

  11. [...] 除了易用的接口之外,它在性能上也表现不凡:http://alecmce.com/as3/events-and-signals-performance-tests [...]

  12. [...] also worth noting that there are many other benefits to using AS3-Signals, for example they provide significant speed improvements over using Events, not just the ability to define them in interfaces. Posted by Mark on March [...]

  13. [...] Robert Penner, I owe you for that one; you are the man. AS3Signals is simply fantastic. With different tests showing the speed of this event mechanism and a presentation and a video tutorial showing how [...]

  14. Recently I've tried to build a signal system with my own implementation, with performance kept in mind, and here's what came out.
    http://cjcat.blogspot.com/2010/07/cjsignals-my-...

    I've come up with an approach to handle listener adding and removal efficiently. Thought you might be interested.
    http://cjcat.blogspot.com/2010/07/performance-i...

    Cheers :)

    Allen Chou

    8 Jul 10 at 4:46 am

Leave a Reply

blog comments powered by Disqus