Loading ...
Sorry, an error occurred while loading the content.

Re: new Array(n)

Expand Messages
  • pauanyu
    ... Very interesting. I find it unintuitive how using arrays to work with strings can actually be faster than working directly with strings... yet here we are.
    Message 1 of 11 , Jun 6, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "benxwhite" <ben.a.white@...> wrote:
      >
      > //Method 4
      > var foo = [];
      > foo.length = n + 1;
      > foo = foo.join('*');
      >
      > Method 4 compared very similar to Method 1 in speed, and actually slightly faster. (approximately 10-40% in my tests)
      > It was not the fastest in every browser, but was the most consistent in performance across browsers.
      >
      > I would suggest Method 4 for best performance, and Method 1 for cleanest.
      >

      Very interesting. I find it unintuitive how using arrays to work with strings can actually be faster than working directly with strings... yet here we are.

      40% faster, you say? That's impressive, given how both appear to do exactly the same thing. It probably has to do with the fact that "new Array" does different things depending on what you pass to it.
    Your message has been successfully submitted and would be delivered to recipients shortly.