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
concatpushpopshiftunshift
Understandably, the following methods don’t fit the paradigm of an array with a required, immutable length:
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.
One Trackback
[...] This post was mentioned on Twitter by Al Mac and rick waldron, Nick Cammarata. Nick Cammarata said: RT @rwaldron: New Blog: Javascript Typed Arrays in Firefox 4: Array Method Support http://gul.ly/9d #javascript #firefox [...]