Math.minmax
T.J. Crowder
tj.crowder at farsightsoftware.com
Thu Jun 29 08:49:49 UTC 2017
On Thu, Jun 29, 2017 at 9:19 AM, Florian Bösch <pyalot at gmail.com> wrote:
> > Improve performance
>
> I doubt that this sequence of calls:
>
> min = Math.min(min, value)
> max = Math.max(max, value)
>
>
> Is slower than this:
>
> [min,max] = Math.minmax([min,max,value])
>
> Because while the former can get inlined by JIT, the latter can't,
> and on top, it allocates 2 objects which then have to be GC'ed.
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).
Now, that's comparing making calls to functions defined in userland, not
ones provided by the engine, so that's an important difference. And there's
basically no memory pressure, whereas in real life there may be. And it's a
synthetic benchmark. But there we are.
-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170629/6010aede/attachment.html>
More information about the es-discuss
mailing list