Comment #6 on issue 3807 by [email protected]: String#includes() is
26% slower than String#indexOf
https://code.google.com/p/v8/issues/detail?id=3807#c6
The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/d20a5090428e9abaa9e994cca7468955666fd24f
commit d20a5090428e9abaa9e994cca7468955666fd24f
Author: littledan <[email protected]>
Date: Wed Jul 15 01:01:42 2015
Optimize String.prototype.includes
This patch removes the MathMax call from String.prototype.includes
in order to improve performance. With some quick and dirty benchmarking,
(test case courtesy of the node folks) a sizable performance gain is
visible:
d8> function testIndexOf() { var stringArray =
[ 'hello', 'world', '123', 'abc' ]; return stringArray.some(function(val,
idx, arr) { return val.indexOf('world') !== -1 })}
d8> function testIncludes() { var stringArray =
[ 'hello', 'world', '123', 'abc' ]; return stringArray.some(function(val,
idx, arr) { return val.includes('world') })}
d8> function testTime(fn) { var before = Date.now(); fn(); return
Date.now() - before; }
d8> testTime(function() { for (var i = 0; i < 10000000; i++) {
testIncludes() } })
2244
d8> testTime(function() { for (var i = 0; i < 10000000; i++) {
testIndexOf() } })
2212
Compare that to before the test, when the performance difference was much
larger:
d8> testTime(function() { for (var i = 0; i < 10000000; i++) {
testIndexOf() } })
2223
d8> testTime(function() { for (var i = 0; i < 10000000; i++) {
testIncludes() } })
2650
In my runs, performance of both functions drifts up and down, but running
them in quick
succession back and forth shows a roughly consistent delta of about this
magnitude.
String.prototype.includes is still slightly (maybe 5%) slower than
String.prototype.indexOf,
but the effect is significantly reduced.
R=adamk
BUG=v8:3807
LOG=Y
Review URL: https://codereview.chromium.org/1231673008
Cr-Commit-Position: refs/heads/master@{#29665}
[modify]
http://crrev.com/d20a5090428e9abaa9e994cca7468955666fd24f/src/string.js
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.