Commit 774f65e4 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[js-perf-test] Add assert and assertEquals

Drive-by-fix:
- Remove obsolete mark_shared_functions_for_tier_up flag

Bug: chromium:873728
Change-Id: I6c18b2e55068be913a3fc16932a9be0f9f02b635
Reviewed-on: https://chromium-review.googlesource.com/1173232
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55101}
parent 585e3d16
......@@ -43,13 +43,6 @@
})();
(() => {
function assert(condition, message) {
if (!condition) {
throw Error(message);
}
}
const A = new Array(1000);
for (let i = 0; i < A.length; i++) {
......
......@@ -11,12 +11,6 @@ for (let i = 0; i < kArraySize; ++i) {
let array_to_sort = [];
function assert(condition, message) {
if (!condition) {
throw Error(message);
}
}
function AssertPackedSmiElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasSmiElements(array_to_sort),
......
......@@ -186,7 +186,7 @@
"path": ["Closures"],
"main": "run.js",
"resources": ["closures.js"],
"flags": ["--mark_shared_functions_for_tier_up"],
"flags": [],
"results_regexp": "^%s\\-Closures\\(Score\\): (.+)$",
"tests": [
{"name": "Closures"}
......
......@@ -2,37 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function assert(expression, message) {
if (typeof expression === "string" && message === void 0) {
message = expression;
expression = eval(expression);
}
if (!expression) {
var lines = ["Benchmark Error"];
if (message !== void 0) {
lines = ["Benchmark Error:", String(message)];
}
throw new Error(lines.join("\n"));
}
return true;
}
assert.same = function(expected, actual, message) {
var isSame =
expected === actual || typeof expected !== expected && actual !== actual;
if (!isSame) {
var details = `Expected: ${String(expected)}\n` +
`But found: ${String(actual)}`;
var lines = ["Benchmark Error:", details];
if (message !== void 0) {
lines = ["Benchmark Error:", details, "", String(message)];
}
throw new Error(lines.join("\n"));
}
return true;
}
new BenchmarkSuite('Spread_OneByteShort', [1000], [
new Benchmark('test', false, false, 0,
Spread_OneByteShort, Spread_OneByteShortSetup,
......@@ -52,8 +21,8 @@ function Spread_OneByteShort() {
function Spread_OneByteShortTearDown() {
var expected = "A|l|p|h|a|b|e|t|-|S|o|u|p";
return assert("Array.isArray(result)")
&& assert.same(expected, result.join("|"));
return assert(Array.isArray(result))
&& assertEquals(expected, result.join("|"));
}
// ----------------------------------------------------------------------------
......@@ -75,8 +44,8 @@ function Spread_TwoByteShort() {
function Spread_TwoByteShortTearDown() {
var expected = "\u5FCD|\u8005|\u306E|\u653B|\u6483";
return assert("Array.isArray(result)")
&& assert.same(expected, result.join("|"));
return assert(Array.isArray(result))
&& assertEquals(expected, result.join("|"));
}
// ----------------------------------------------------------------------------
......@@ -100,8 +69,8 @@ function Spread_WithSurrogatePairsShort() {
function Spread_WithSurrogatePairsShortTearDown() {
var expected =
"\uD83C\uDF1F|\u5FCD|\u8005|\u306E|\u653B|\u6483|\uD83C\uDF1F";
return assert("Array.isArray(result)")
&& assert.same(expected, result.join("|"));
return assert(Array.isArray(result))
&& assertEquals(expected, result.join("|"));
}
// ----------------------------------------------------------------------------
......@@ -123,7 +92,7 @@ function ForOf_OneByteShort() {
}
function ForOf_OneByteShortTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
// ----------------------------------------------------------------------------
......@@ -145,7 +114,7 @@ function ForOf_TwoByteShort() {
}
function ForOf_TwoByteShortTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
// ----------------------------------------------------------------------------
......@@ -168,7 +137,7 @@ function ForOf_WithSurrogatePairsShort() {
}
function ForOf_WithSurrogatePairsShortTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
// ----------------------------------------------------------------------------
......@@ -190,7 +159,7 @@ function ForOf_OneByteLong() {
}
function ForOf_OneByteLongTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
// ----------------------------------------------------------------------------
......@@ -212,7 +181,7 @@ function ForOf_TwoByteLong() {
}
function ForOf_TwoByteLongTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
// ----------------------------------------------------------------------------
......@@ -235,5 +204,5 @@ function ForOf_WithSurrogatePairsLong() {
}
function ForOf_WithSurrogatePairsLongTearDown() {
return assert.same(string, result);
return assertEquals(string, result);
}
......@@ -373,3 +373,23 @@ BenchmarkSuite.prototype.RunStep = function(runner) {
// Start out running the setup.
return RunNextSetup();
}
function assert(condition, message) {
if (!condition) throw Error(message);
}
function assertEquals(expected, actual, message) {
var isSame =
expected === actual || typeof expected !== expected && actual !== actual;
if (isSame) return true;
var details = `Expected: ${String(expected)}\n` +
`But found: ${String(actual)}`;
var lines = ["Benchmark Error:", details];
if (message !== undefined) {
lines = ["Benchmark Error:", details, "", String(message)];
}
throw new Error(lines.join("\n"));
}
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