Commit 07e163bd authored by bmeurer's avatar bmeurer Committed by Commit bot

[js-perf-test] Add microbenchmarks for materialized rest parameters.

Functions that take mandatory parameters plus a number of optional
parameters, that need to be materialized as an Array are quite common.
The simplest possible case of this is essentially:

  function foo(mandatory, ...args) { return args; }

Babel translates this to something like:

  function foo(mandatory) {
    "use strict";
    for (var _len = arguments.length,
             args = Array(_len > 1 ? _len - 1 : 0),
             _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }
    return args;
  }

The key to great performance here is to make sure that we don't
materialize the (unmapped) arguments object in this case, plus that we
have some kind of fast-path for the Array constructor and the
initialization loop.

This microbenchmark ensures that we have decent performance even in the
case where the assignment to args is polymorphic, i.e. the arguments
have seen different elements kinds, starting with FAST_HOLEY_ELEMENTS
and then FAST_HOLEY_SMI_ELEMENTS.

R=yangguo@chromium.org
BUG=v8:6262

Review-Url: https://codereview.chromium.org/2823343004
Cr-Commit-Position: refs/heads/master@{#44709}
parent c0ccdb57
......@@ -65,7 +65,9 @@
"units": "score",
"results_regexp": "^%s\\-RestParameters\\(Score\\): (.+)$",
"tests": [
{"name": "Basic1"}
{"name": "Basic1"},
{"name": "ReturnArgsBabel"},
{"name": "ReturnArgsNative"}
]
},
{
......
......@@ -7,6 +7,18 @@ new BenchmarkSuite('Basic1', [1000], [
BasicRest1, BasicRest1Setup, BasicRest1TearDown)
]);
new BenchmarkSuite('ReturnArgsBabel', [10000], [
new Benchmark('ReturnArgsBabel', false, false, 0,
ReturnArgsBabel, ReturnArgsBabelSetup,
ReturnArgsBabelTearDown)
]);
new BenchmarkSuite('ReturnArgsNative', [10000], [
new Benchmark('ReturnArgsNative', false, false, 0,
ReturnArgsNative, ReturnArgsNativeSetup,
ReturnArgsNativeTearDown)
]);
// ----------------------------------------------------------------------------
var result;
......@@ -28,3 +40,57 @@ function BasicRest1() {
function BasicRest1TearDown() {
return result == 550;
}
// ----------------------------------------------------------------------------
var length = 50;
var numbers = Array.apply(null, {length}).map(Number.call, Number);
var strings = numbers.map(String.call, String);
function ReturnArgsBabelFunction(unused) {
"use strict";
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0),
_key = 1;
_key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return args;
}
function ReturnArgsBabelSetup() {
// Warm up with FAST_HOLEY_ELEMENTS
result = ReturnArgsBabelFunction(...strings);
// Warm up with FAST_HOLEY_SMI_ELEMENTS
result = ReturnArgsBabelFunction(...numbers);
}
function ReturnArgsBabel() {
result = ReturnArgsBabelFunction(...strings);
result = ReturnArgsBabelFunction(...numbers);
}
function ReturnArgsBabelTearDown() {
return result.indexOf(0) === 0;
}
// ----------------------------------------------------------------------------
function ReturnArgsNativeFunction(unused, ...args) {
return args;
}
function ReturnArgsNativeSetup() {
// Warm up with FAST_HOLEY_ELEMENTS
result = ReturnArgsNativeFunction(...strings);
// Warm up with FAST_HOLEY_SMI_ELEMENTS
result = ReturnArgsNativeFunction(...numbers);
}
function ReturnArgsNative() {
result = ReturnArgsNativeFunction(...strings);
result = ReturnArgsNativeFunction(...numbers);
}
function ReturnArgsNativeTearDown() {
return result.indexOf(0) === 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment