Commit 9feefafa authored by jgruber's avatar jgruber Committed by Commit bot

[js-perf-test] Add a basic async-await microbenchmark

These benchmarks are intended to compare the overhead of async-await vs.
a naive promise implementation vs. the babel async-await transformation.
The functions in the benchmark don't do any work themselves, so results
should reflect only overhead of the chosen implementation.

Current numbers on my local machine (higher is better):

BaselineES2017-AsyncAwait(Score): 2006
BaselineNaivePromises-AsyncAwait(Score): 7470
Native-AsyncAwait(Score): 3640

BUG=v8:5639

Review-Url: https://codereview.chromium.org/2577393002
Cr-Commit-Position: refs/heads/master@{#41860}
parent e54e2dd9
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
new BenchmarkSuite('BaselineES2017', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
function _asyncToGenerator(fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
return Promise.resolve(value)
.then(function (value) {
step("next", value);
}, function (err) {
step("throw", err);
});
}
}
return step("next");
});
};
}
var a, b, c, d, e, f, g, h, i, j, x;
function Setup() {
x = Promise.resolve();
j = (() => {
var _ref = _asyncToGenerator(function* () {
return x;
});
function j() {
return _ref.apply(this, arguments);
}
return j;
})();
i = (() => {
var _ref2 = _asyncToGenerator(function* () {
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
yield j();
return j();
});
function i() {
return _ref2.apply(this, arguments);
}
return i;
})();
h = (() => {
var _ref3 = _asyncToGenerator(function* () {
return i();
});
function h() {
return _ref3.apply(this, arguments);
}
return h;
})();
g = (() => {
var _ref4 = _asyncToGenerator(function* () {
return h();
});
function g() {
return _ref4.apply(this, arguments);
}
return g;
})();
f = (() => {
var _ref5 = _asyncToGenerator(function* () {
return g();
});
function f() {
return _ref5.apply(this, arguments);
}
return f;
})();
e = (() => {
var _ref6 = _asyncToGenerator(function* () {
return f();
});
function e() {
return _ref6.apply(this, arguments);
}
return e;
})();
d = (() => {
var _ref7 = _asyncToGenerator(function* () {
return e();
});
function d() {
return _ref7.apply(this, arguments);
}
return d;
})();
c = (() => {
var _ref8 = _asyncToGenerator(function* () {
return d();
});
function c() {
return _ref8.apply(this, arguments);
}
return c;
})();
b = (() => {
var _ref9 = _asyncToGenerator(function* () {
return c();
});
function b() {
return _ref9.apply(this, arguments);
}
return b;
})();
a = (() => {
var _ref10 = _asyncToGenerator(function* () {
return b();
});
function a() {
return _ref10.apply(this, arguments);
}
return a;
})();
%RunMicrotasks();
}
function Basic() {
a();
%RunMicrotasks();
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
new BenchmarkSuite('BaselineNaivePromises', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
var a,b,c,d,e,f,g,h,i,j,x;
function Setup() {
x = Promise.resolve();
j = function j(p) { return p; };
i = function i(p) {
return p.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j)
.then(j);
};
h = function h(p) { return p; };
g = function g(p) { return p; };
f = function f(p) { return p; };
e = function e(p) { return p; };
d = function d(p) { return p; };
c = function c(p) { return p; };
b = function b(p) { return p; };
a = function a(p) { return p; };
%RunMicrotasks();
}
function Basic() {
x.then(j)
.then(i)
.then(h)
.then(g)
.then(f)
.then(e)
.then(d)
.then(c)
.then(b)
.then(a);
%RunMicrotasks();
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
new BenchmarkSuite('Native', [1000], [
new Benchmark('Basic', false, false, 0, Basic, Setup),
]);
var a,b,c,d,e,f,g,h,i,j,x;
function Setup() {
x = Promise.resolve();
j = async function j() { return x; };
i = async function i() {
await j();
await j();
await j();
await j();
await j();
await j();
await j();
await j();
await j();
return j();
};
h = async function h() { return i(); };
g = async function g() { return h(); };
f = async function f() { return g(); };
e = async function e() { return f(); };
d = async function d() { return e(); };
c = async function c() { return d(); };
b = async function b() { return c(); };
a = async function a() { return b(); };
%RunMicrotasks();
}
function Basic() {
a();
%RunMicrotasks();
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load('../base.js');
load('baseline-babel-es2017.js');
load('baseline-naive-promises.js');
load('native.js');
var success = true;
function PrintResult(name, result) {
print(name + '-AsyncAwait(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });
......@@ -8,6 +8,18 @@
"total": true,
"resources": ["base.js"],
"tests": [
{
"name": "AsyncAwait",
"path": ["AsyncAwait"],
"main": "run.js",
"resources": [
"native.js",
"baseline-babel-es2017.js",
"baseline-naive-promises.js"
],
"flags": ["--allow-natives-syntax"],
"results_regexp": "^%s\\-AsyncAwait\\(Score\\): (.+)$"
},
{
"name": "Generators",
"path": ["Generators"],
......
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