Hacker News new | past | comments | ask | show | jobs | submit login

SitePoint swallowed my comment, so I'll just post it here:

I found some of your claims questionable, so I cherry-picked one to test for myself.

  This code converts arguments[i] to a string object using the
  String conversion function. This is possibly the slowest way to
  perform such a conversion, although it would be the most
  obvious to many developers coming from other languages.

  Much quicker is to add an empty string ("") to the value you
  wish to convert:
I compared the time it took to run 100,000 of each of String(fn) and fn + "", and found that the results were more ambiguous and less definitive than your assertion. In fact, fn + "" was 6.6% faster on Firefox 3.5, but 15.8% slower on a recent Chromium build. In any case, the difference was, even over 100,000 runs, a few milliseconds, so it hardly seems like this particular case would be an area to focus on for optimization.

I wonder how many of your other strong claims would stand up to similar testing.

Test code and results: http://gist.github.com/232944




I've done a lot of testing on creating strings by concatenation and it turns out that + is actually one of the slowest. It's much faster, for example, to create an array and then join it with "". Maybe try that in your test and see how it compares.

Example:

  x = []
  x.push("latortuga")
  x.push(" is so right")
  str = x.join("")


That's a different issue than the what the OP was writing about, which is getting a string representation of an object, in this case, a function.


This used to be true in Python as well, but I'm not sure if it still holds for recent versions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: