Learning JavaScript/jsPerf.com

Instantiation vs. direct inheritance

 * http://jsperf.com/plain-object-inheritance-vs-instantiating-constructors

This is micro-optimisation and very different depending on which browser. Don't base design decisions on this this perf detail.

-- Krinkle (talk) 09:32, 10 January 2013 (UTC)

Accessing object members

 * http://jsperf.com/performance-impact-of-accessing-length-in-for-loop

Often in code we see constructions like this: or even:

The reason is because this way the part of the for-syntax that is is evaluated after every loop (the middle part between the two semi-colons ) does not have to look up the length of the array, instead it is cached in a local variable (using a combined  statement in the initializing part of the for-syntax).

For numbers see the jsPerf

--Krinkle 23:35, 12 August 2011 (UTC)

Comma seperated IDs or $.fn.add passing quickExpr

 * http://jsperf.com/comma-seperated-ids-or-fn-add-passing-quickexpr

Unless the query is rerouted to a native browser API, using .add will always be faster since those strings will pass quickExpr and not initiate the Sizzle selector engine at all.

However with more browsers going to support the native API (document.querySelectorAll), eventually one comma seperated list followed by 1 query to the browser's API will be faster.

In the test results the browsers having document.querySelectorAll show the first test is faster, in other browsers (most of them as of writing) the second will be faster.

--Krinkle 09:53, 22 May 2011 (UTC)