Anyone have any articles / tests on the performance of the is operator? I can’t find anything on Google, it’s just eating my “is” keyword as being too small.
I plan to use the is operator extensively in a messaging system for my components and so performance needs to be solid. It’ll save me from having to come up with a scheme of ids and id-lookups for each message if I can just do:
function onMessage(message : Message, type : Class) : void
{
switch(type)
{
case MessageOne:
// whatever
break;
case MessageTwo:
// whatever
break;
}
}
The timing tests I’ve done show it’s almost as fast as an integer comparison, so I just want to make sure.
Anyone done their own tests or know some articles?
Thanks.
The “is” operator is plenty fast, even at tens of thousands of tests per second.
Not only that, it really is a best practice for comparing inheritance hierarchy, not just class name (so comparing if
Image is UIComponentfor example) as well as support for implementation of interfaces (so comparingImage is IEventDispatcherfor example).More: http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_09.html#122921
So, yes, it’s fast enough – and, if it wasn’t and you’re having to break the foundational best practices of the language to bend it to the will of your design – then you’re doing it wrong.
🙂