[js-perf-test] add microbenchmarks for String Iterators
Add some micro-benchmarks to help measure the impact and benefit of String Iterator optimizations. BUG=v8:5388 R=bmeurer@chromium.org Review-Url: https://codereview.chromium.org/2364743003 Cr-Commit-Position: refs/heads/master@{#39690}
This commit is contained in:
parent
d7858e35f6
commit
72d5c98e90
@ -123,6 +123,24 @@
|
||||
{"name": "StringFunctions"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringIterators",
|
||||
"path": ["StringIterators"],
|
||||
"main": "run.js",
|
||||
"resources": ["string-iterator.js"],
|
||||
"results_regexp": "^%s\\-StringIterators\\(Score\\): (.+)$",
|
||||
"tests": [
|
||||
{"name": "Spread_OneByteShort"},
|
||||
{"name": "Spread_TwoByteShort"},
|
||||
{"name": "Spread_WithSurrogatePairsShort"},
|
||||
{"name": "ForOf_OneByteShort"},
|
||||
{"name": "ForOf_TwoByteShort"},
|
||||
{"name": "ForOf_WithSurrogatePairsShort"},
|
||||
{"name": "ForOf_OneByteLong"},
|
||||
{"name": "ForOf_TwoByteLong"},
|
||||
{"name": "ForOf_WithSurrogatePairsLong"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Templates",
|
||||
"path": ["Templates"],
|
||||
|
27
test/js-perf-test/StringIterators/run.js
Normal file
27
test/js-perf-test/StringIterators/run.js
Normal file
@ -0,0 +1,27 @@
|
||||
// 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('string-iterator.js');
|
||||
|
||||
|
||||
var success = true;
|
||||
|
||||
function PrintResult(name, result) {
|
||||
print(name + '-StringIterators(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 });
|
239
test/js-perf-test/StringIterators/string-iterator.js
Normal file
239
test/js-perf-test/StringIterators/string-iterator.js
Normal file
@ -0,0 +1,239 @@
|
||||
// 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.
|
||||
|
||||
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,
|
||||
Spread_OneByteShortTearDown),
|
||||
]);
|
||||
|
||||
var result;
|
||||
var string;
|
||||
function Spread_OneByteShortSetup() {
|
||||
result = undefined;
|
||||
string = "Alphabet-Soup";
|
||||
}
|
||||
|
||||
function Spread_OneByteShort() {
|
||||
result = [...string];
|
||||
}
|
||||
|
||||
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("|"));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('Spread_TwoByteShort', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
Spread_TwoByteShort, Spread_TwoByteShortSetup,
|
||||
Spread_TwoByteShortTearDown),
|
||||
]);
|
||||
|
||||
function Spread_TwoByteShortSetup() {
|
||||
result = undefined;
|
||||
string = "\u5FCD\u8005\u306E\u653B\u6483";
|
||||
}
|
||||
|
||||
function Spread_TwoByteShort() {
|
||||
result = [...string];
|
||||
}
|
||||
|
||||
function Spread_TwoByteShortTearDown() {
|
||||
var expected = "\u5FCD|\u8005|\u306E|\u653B|\u6483";
|
||||
return assert("Array.isArray(result)")
|
||||
&& assert.same(expected, result.join("|"));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('Spread_WithSurrogatePairsShort', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
Spread_WithSurrogatePairsShort,
|
||||
Spread_WithSurrogatePairsShortSetup,
|
||||
Spread_WithSurrogatePairsShortTearDown),
|
||||
]);
|
||||
|
||||
function Spread_WithSurrogatePairsShortSetup() {
|
||||
result = undefined;
|
||||
string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F";
|
||||
}
|
||||
|
||||
function Spread_WithSurrogatePairsShort() {
|
||||
result = [...string];
|
||||
}
|
||||
|
||||
function Spread_WithSurrogatePairsShortTearDown() {
|
||||
var expected =
|
||||
"\uD83C\uDF1F|\u5FCD|\u8005|\u306E|\u653B|\u6483|\uD83C\uDF1F";
|
||||
return assert("Array.isArray(result)")
|
||||
&& assert.same(expected, result.join("|"));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_OneByteShort', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_OneByteShort, ForOf_OneByteShortSetup,
|
||||
ForOf_OneByteShortTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_OneByteShortSetup() {
|
||||
result = undefined;
|
||||
string = "Alphabet-Soup";
|
||||
}
|
||||
|
||||
function ForOf_OneByteShort() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_OneByteShortTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_TwoByteShort', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_TwoByteShort, ForOf_TwoByteShortSetup,
|
||||
ForOf_TwoByteShortTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_TwoByteShortSetup() {
|
||||
result = undefined;
|
||||
string = "\u5FCD\u8005\u306E\u653B\u6483";
|
||||
}
|
||||
|
||||
function ForOf_TwoByteShort() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_TwoByteShortTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_WithSurrogatePairsShort', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_WithSurrogatePairsShort,
|
||||
ForOf_WithSurrogatePairsShortSetup,
|
||||
ForOf_WithSurrogatePairsShortTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_WithSurrogatePairsShortSetup() {
|
||||
result = undefined;
|
||||
string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F";
|
||||
}
|
||||
|
||||
function ForOf_WithSurrogatePairsShort() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_WithSurrogatePairsShortTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_OneByteLong', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_OneByteLong, ForOf_OneByteLongSetup,
|
||||
ForOf_OneByteLongTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_OneByteLongSetup() {
|
||||
result = undefined;
|
||||
string = "Alphabet-Soup|".repeat(128);
|
||||
}
|
||||
|
||||
function ForOf_OneByteLong() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_OneByteLongTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_TwoByteLong', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_OneByteLong, ForOf_OneByteLongSetup,
|
||||
ForOf_OneByteLongTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_TwoByteLongSetup() {
|
||||
result = undefined;
|
||||
string = "\u5FCD\u8005\u306E\u653B\u6483".repeat(128);
|
||||
}
|
||||
|
||||
function ForOf_TwoByteLong() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_TwoByteLongTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
new BenchmarkSuite('ForOf_WithSurrogatePairsLong', [1000], [
|
||||
new Benchmark('test', false, false, 0,
|
||||
ForOf_WithSurrogatePairsLong, ForOf_WithSurrogatePairsLongSetup,
|
||||
ForOf_WithSurrogatePairsLongTearDown),
|
||||
]);
|
||||
|
||||
function ForOf_WithSurrogatePairsLongSetup() {
|
||||
result = undefined;
|
||||
string = "\uD83C\uDF1F\u5FCD\u8005\u306E\u653B\u6483\uD83C\uDF1F|"
|
||||
.repeat(128);
|
||||
}
|
||||
|
||||
function ForOf_WithSurrogatePairsLong() {
|
||||
result = "";
|
||||
for (var c of string) result += c;
|
||||
}
|
||||
|
||||
function ForOf_WithSurrogatePairsLongTearDown() {
|
||||
return assert.same(string, result);
|
||||
}
|
Loading…
Reference in New Issue
Block a user