I'm an Austrian living in Austria, and I used to put my eggs in the fridge. Then I stopped doing that because my spouse thinks they absorb the smell of the fridge and now I don't.
The store I usually buy my eggs from doesn't store them in a fridge. Other stores do.
Most eggs I buy at the supermarket don't seem to be washed or sanitized.
It is a shitty generalization slandering all articles which (possibly poorly) chose a question as headline.
This is obviously an "article" where the author was legitimately interested in answering the question in the title. This is one of the cases where Betteridge's law does not apply.
Betteridge's law may be useful to remind people to watch out for poor journalism and fact checking. In that case, I propose that all articles shall henceforth use questions as titles because people should do that anyway.
It's funny because author at the conclusions basically says that it is useful and people should use it hence the answer to question "Is TDD Dead?" is No.
There's something going on with the perf tests - most of that code is being optimised away, in one case I got over a billion cycles per second. The trick to these things is writing code which cannot be optimised away, like returning Math.random() from a function and using the return value to increment another variable.
Yes. At present if you want a jsperf test to be remotely accurate:
1) It shouldn't exercise the GC. GC pressure totally skews jsperf results in a way it can't compensate for.
2) It should compute a result on every iteration that is checked at the end to make sure it is accurate. (This ensures that the compiler can't optimize out unused results from your benchmark loop)
3) The check should have actual control flow so it can't be ignored.
It's also worthwhile to warm all your test cases once in the setup portion of the page before the loop runs. Some performance issues only appear once you've passed multiple argument types into a function, so if you run a test case that passes in ints, and then run a test case that passes in floats, the second test case will be slower for no obvious reason. You can swap the test cases around and the second run will still be slower.
(There are actually a huge list of problems with javascript microbenchmarks, and jsperf only adds to them by being low quality software. Please use it sparingly.)
The article is "optimisation killers", you're right about caching the array length lookup check being faster, but it doesn't kill V8's ability to optimise functions like the rest of the examples do
`for ... in` is a relatively slow construct anyway, the faster option (a lot more verbose) is:
var keys = Object.keys(obj),
length = keys.length,
key, i;
for (i = 0; i < length; i++) {
key = keys[i];
}
While this is not exactly the same as for..in, it usually behaves how you'd expect and is significantly faster for a couple of reasons:
1. In a for..in loop the engine must keep track of the keys already iterated over, whereas in the fast version we can simply increment a counter and do a fast array lookup.
2. It's possible to add properties to the object that you're iterating within the body of the for..in statement, and these will be iterated too. Doing such a thing is obviously very rare but it's the kind of edge case the JS engine must keep track of.
Your mileage will vary depending on the browser. If you really care (as in profiling identified this as a hotspot) you should measure the alternatives you're considering.
But note that in your specific case chances are the cost of a bunch of console.log() calls completely swamps the cost of either a for loop or a forEach call. console.log() has _incredibly_ complicated behavior.
no, but I could probably have worded it better. What I mean to say is that if you do this in JS:
function add (a, b) {
return a + b;
}
and this in C:
int add(int a,int b)
{
return a + b;
}
you're going to get essentially the same performance.
The latter sentence you quoted refers to the specific builtin functions that fast.js re-implements. So we first get close to native performance in JS, then we beat the builtin functions by doing less work overall.