There’s an interesting tidbit of information on jacksondunstan.com about using casts when accessing data from a data structure to gain performance. As tests show this is true for all tested structures (Array, Vector, Dictionary, Object and Dynamic Class) but what is even more impressive is the difference of how to cast. As the results below will show it’s always significantly faster to use the “as” operator for casting than the conventional method of using braces “()”. This comes as somewhat of a surprise for me as I’ve been always under the impression that the opposite is true. However that might have been still based on outdated tests done on older Flash runtimes.
Note that this performance gain will only show in the release Flash Player. In the Debug player you will likely get the opposite result that using the “as” operator is slower so be sure you are testing in the release runtime.
Here are my results:
*** Casted Lookup Performance Test *** Runtime: 11.0.1 (60), PlugIn, WIN, Debugger: false Click to begin test! Running 10000000 iterations ... Finished! All results in milliseconds, smaller is better. TYPE NO CAST CAST AS CAST () ---------------------------------------------- Array 75 42 249 Vector 71 37 244 Dictionary 219 182 382 Object 202 172 380 Dynamic Class 212 178 377 SUM 779 611 1632
