This is the Bocoup web log with posts from Al, Ben, Boaz, Darius, Greg, Irene, John, Mike, Nate, Nick, Pete, Richard, Rick, Sam, Sam Clearman, Scott and Tim. You should also make sure to checkout code.bocoup.com, where we keep the finished versions of ideas we kick around here.



Jul 15, 2010

Javascript Typed Arrays: Method Support

Al MacDonald recently posted http://weblog.bocoup.com/javascript-typed-arrays - which is an interesting look at the benchmarkable speed differences between FireFox 4’s Float32Array constructor and the traditional Array constructor.


As expected, the Typed Arrays are definitively faster due entirely to native optimization: they only allow integer or floating point numbers (respectively to their Int or Float prefix); additionally length is required and immutable.


What about the nitty gritty? I whipped up a basic test suite to check support for methods of the traditional Array object - take a look:


  • + supported
  • - unsupported


  • Understandably, the following methods don't fit the paradigm of an array with a required, immutable length:
    • concat
    • push
    • pop
    • shift
    • unshift
    But I fail to see why "slice" gets preferential treatment (by name in the spec) while other useful methods such as "indexOf", "reverse", "sort", "filter", "forEach", etc are not included in the spec. Note that Firefox 4 supports all of these methods for traditional arrays.

    Want to try these at home? You'll need FireFox 4 Beta 1 and these:


    Get the entire gist here

    JavaScript JS Documentation: JS Array Example: Creating a Two-dimensional Array, JavaScript Array Example: Creating a Two-dimensional Array



Comments:




Please send your questions to this address or call Bocoup at 617-379-2752.
This web page is proudly maintained by Bocoup and hosted by (mt) Media Temple.
All code on this website is Open Source. Want to work at Bocoup? Then Apply.
HTML5 Powered with Connectivity / Realtime, CSS3 / Styling, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage