bzbarsky at mit.edu
Fri Jun 30 06:53:24 UTC 2017
On 6/29/17 1:49 AM, T.J. Crowder wrote:
> I was going to make that very point, backed by a jsPerf, but the jsPerf
> doesn't back it up: https://jsperf.com/two-calls-vs-one-returning-array
> It says the minmax is faster on a 10-entry array (it reports the
> separate calls as 46-48% slower on V8 and SpiderMonkey).
See https://jsperf.com/two-calls-vs-one-no-destructuring/1 which is the
same as the above-linked testcase but doesn't do destructuring of an
array into an arglist and the collapsing of an arglist into an array for
every call. In that one the two-call version is in fact faster.
That is, the cost of allocating and filling the two-element return value
array is much smaller than the cost of allocating and filling the
20-element array. Since the two-call testcase in
https://jsperf.com/two-calls-vs-one-returning-array does the latter
twice, it ends up slower than the version that only does it once.
More information about the es-discuss