[js-perf-tests] Add substring perf tests
This CL also reorganizes the Strings test suite Bug: v8:7340 Change-Id: I54d4d76a16c362e38ebfc9719ac8cb1a490ef3cc Reviewed-on: https://chromium-review.googlesource.com/941122 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#51631}
This commit is contained in:
parent
251f63d82f
commit
4dd446ab47
@ -191,25 +191,82 @@
|
||||
{
|
||||
"name": "Strings",
|
||||
"path": ["Strings"],
|
||||
"main": "run.js",
|
||||
"resources": ["harmony-string.js", "string-indexof.js"],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"timeout": 240,
|
||||
"timeout_arm": 420,
|
||||
"units": "score",
|
||||
"tests": [
|
||||
{"name": "StringFunctions"},
|
||||
{"name": "StringIndexOfConstant"},
|
||||
{"name": "StringIndexOfNonConstant"},
|
||||
{"name": "StringCharCodeAtConstant"},
|
||||
{"name": "StringCharCodeAtNonConstant"},
|
||||
{"name": "StringCharCodeAtConstantInbounds"},
|
||||
{"name": "StringCharCodeAtNonConstantInbounds"},
|
||||
{"name": "StringCodePointAtConstant"},
|
||||
{"name": "StringCodePointAtNonConstant"},
|
||||
{"name": "StringCodePointAtConstantInbounds"},
|
||||
{"name": "StringCodePointAtNonConstantInbounds"}
|
||||
|
||||
{
|
||||
"name": "StringFunctions",
|
||||
"main": "run.js",
|
||||
"resources": [ "harmony-string.js" ],
|
||||
"test_flags": [ "harmony-string" ],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"tests": [
|
||||
{"name": "StringRepeat"},
|
||||
{"name": "StringStartsWith"},
|
||||
{"name": "StringEndsWith"},
|
||||
{"name": "StringIncludes"},
|
||||
{"name": "StringFromCodePoint"},
|
||||
{"name": "StringCodePointAt"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringIndexOf",
|
||||
"main": "run.js",
|
||||
"resources": [ "string-indexof.js" ],
|
||||
"test_flags": [ "string-indexof" ],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"tests": [
|
||||
{"name": "StringIndexOfConstant"},
|
||||
{"name": "StringIndexOfNonConstant"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringAt",
|
||||
"main": "run.js",
|
||||
"resources": [ "string-stringat.js" ],
|
||||
"test_flags": [ "string-stringat" ],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"tests": [
|
||||
{"name": "StringCharCodeAtConstant"},
|
||||
{"name": "StringCharCodeAtNonConstant"},
|
||||
{"name": "StringCharCodeAtConstantInbounds"},
|
||||
{"name": "StringCharCodeAtNonConstantInbounds"},
|
||||
{"name": "StringCodePointAtConstant"},
|
||||
{"name": "StringCodePointAtNonConstant"},
|
||||
{"name": "StringCodePointAtConstantInbounds"},
|
||||
{"name": "StringCodePointAtNonConstantInbounds"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringSubstring",
|
||||
"main": "run.js",
|
||||
"resources": [ "string-substring.js" ],
|
||||
"test_flags": [ "string-substring" ],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"tests": [
|
||||
{"name": "StringDropFirstSlice"},
|
||||
{"name": "StringDropFirstSubstr"},
|
||||
{"name": "StringDropFirstSubstring"},
|
||||
{"name": "StringTakeFirstSlice"},
|
||||
{"name": "StringTakeFirstSubstr"},
|
||||
{"name": "StringTakeFirstSubstring"},
|
||||
{"name": "StringDropLastSlice"},
|
||||
{"name": "StringDropLastSubstr"},
|
||||
{"name": "StringDropLastSubstring"},
|
||||
{"name": "StringTakeLastSlice"},
|
||||
{"name": "StringTakeLastSubstr"},
|
||||
{"name": "StringTakeLastSubstring"},
|
||||
{"name": "StringDropFirstSlice"},
|
||||
{"name": "StringDropFirstSubstr"},
|
||||
{"name": "StringDropFirstSubstring"}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2,19 +2,34 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
new BenchmarkSuite('StringFunctions', [1000], [
|
||||
new BenchmarkSuite('StringRepeat', [10], [
|
||||
new Benchmark('StringRepeat', false, false, 0,
|
||||
Repeat, RepeatSetup, RepeatTearDown),
|
||||
Repeat, RepeatSetup, RepeatTearDown),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringStartsWith', [10], [
|
||||
new Benchmark('StringStartsWith', false, false, 0,
|
||||
StartsWith, WithSetup, WithTearDown),
|
||||
StartsWith, WithSetup, WithTearDown),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringEndsWith', [10], [
|
||||
new Benchmark('StringEndsWith', false, false, 0,
|
||||
EndsWith, WithSetup, WithTearDown),
|
||||
EndsWith, WithSetup, WithTearDown),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringIncludes', [10], [
|
||||
new Benchmark('StringIncludes', false, false, 0,
|
||||
Includes, IncludesSetup, WithTearDown),
|
||||
Includes, IncludesSetup, WithTearDown),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringFromCodePoint', [10000], [
|
||||
new Benchmark('StringFromCodePoint', false, false, 0,
|
||||
FromCodePoint, FromCodePointSetup, FromCodePointTearDown),
|
||||
FromCodePoint, FromCodePointSetup, FromCodePointTearDown),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAt', [1000], [
|
||||
new Benchmark('StringCodePointAt', false, false, 0,
|
||||
CodePointAt, CodePointAtSetup, CodePointAtTearDown),
|
||||
CodePointAt, CodePointAtSetup, CodePointAtTearDown),
|
||||
]);
|
||||
|
||||
|
||||
@ -32,7 +47,7 @@ function Repeat() {
|
||||
|
||||
function RepeatTearDown() {
|
||||
var expected = "";
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
expected += stringRepeatSource;
|
||||
}
|
||||
return result === expected;
|
||||
@ -70,19 +85,20 @@ function Includes() {
|
||||
}
|
||||
|
||||
var MAX_CODE_POINT = 0xFFFFF;
|
||||
const K = 1024;
|
||||
|
||||
function FromCodePointSetup() {
|
||||
result = new Array(MAX_CODE_POINT + 1);
|
||||
result = new Array((MAX_CODE_POINT + 1) / K);
|
||||
}
|
||||
|
||||
function FromCodePoint() {
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i++) {
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
||||
result[i] = String.fromCodePoint(i);
|
||||
}
|
||||
}
|
||||
|
||||
function FromCodePointTearDown() {
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i++) {
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
||||
if (i !== result[i].codePointAt(0)) return false;
|
||||
}
|
||||
return true;
|
||||
@ -92,8 +108,8 @@ function FromCodePointTearDown() {
|
||||
var allCodePoints;
|
||||
|
||||
function CodePointAtSetup() {
|
||||
allCodePoints = new Array(MAX_CODE_POINT + 1);
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i++) {
|
||||
allCodePoints = new Array((MAX_CODE_POINT + 1) / K);
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
||||
allCodePoints = String.fromCodePoint(i);
|
||||
}
|
||||
result = undefined;
|
||||
@ -101,11 +117,11 @@ function CodePointAtSetup() {
|
||||
|
||||
function CodePointAt() {
|
||||
result = 0;
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i++) {
|
||||
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
||||
result += allCodePoints.codePointAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
function CodePointAtTearDown() {
|
||||
return result === MAX_CODE_POINT * (MAX_CODE_POINT + 1) / 2;
|
||||
return result === (MAX_CODE_POINT / K) * ((MAX_CODE_POINT / K) + 1) / 2;
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
|
||||
|
||||
load('../base.js');
|
||||
load('harmony-string.js');
|
||||
load('string-indexof.js');
|
||||
|
||||
load(arguments[0] + '.js');
|
||||
|
||||
var success = true;
|
||||
|
||||
|
@ -34,129 +34,3 @@ function StringIndexOfNonConstant() {
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtConstant', [3], [
|
||||
new Benchmark('StringCharCodeAtConstant', true, false, 0,
|
||||
StringCharCodeAtConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtNonConstant', [3], [
|
||||
new Benchmark('StringCharCodeAtNonConstant', true, false, 0,
|
||||
StringCharCodeAtNonConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtConstantInbounds', [3], [
|
||||
new Benchmark('StringCharCodeAtConstantInbounds', true, false, 0,
|
||||
StringCharCodeAtConstantInbounds),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtNonConstantInbounds', [3], [
|
||||
new Benchmark('StringCharCodeAtNonConstantInbounds', true, false, 0,
|
||||
StringCharCodeAtNonConstantInbounds),
|
||||
]);
|
||||
|
||||
const string = "qweruiplkjhgfdsazxccvbnm";
|
||||
const indices = [1, 13, 32, 100, "xx"];
|
||||
const indicesInbounds = [1, 7, 13, 17, "xx"];
|
||||
|
||||
function StringCharCodeAtConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indices[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtNonConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indices[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indicesInbounds[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtNonConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indicesInbounds[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtConstant', [3], [
|
||||
new Benchmark('StringCodePointAtConstant', true, false, 0,
|
||||
StringCodePointAtConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtNonConstant', [3], [
|
||||
new Benchmark('StringCodePointAtNonConstant', true, false, 0,
|
||||
StringCodePointAtNonConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtConstantInbounds', [3], [
|
||||
new Benchmark('StringCodePointAtConstantInbounds', true, false, 0,
|
||||
StringCodePointAtConstantInbounds),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtNonConstantInbounds', [3], [
|
||||
new Benchmark('StringCodePointAtNonConstantInbounds', true, false, 0,
|
||||
StringCodePointAtNonConstantInbounds),
|
||||
]);
|
||||
|
||||
const unicode_string = "qweräϠ<C3A4>𝌆krefdäϠ<C3A4>𝌆ccäϠ<C3A4>𝌆";
|
||||
|
||||
function StringCodePointAtConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indices[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtNonConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indices[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indicesInbounds[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtNonConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indicesInbounds[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
129
test/js-perf-test/Strings/string-stringat.js
Normal file
129
test/js-perf-test/Strings/string-stringat.js
Normal file
@ -0,0 +1,129 @@
|
||||
// Copyright 2017 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('StringCharCodeAtConstant', [3], [
|
||||
new Benchmark('StringCharCodeAtConstant', true, false, 0,
|
||||
StringCharCodeAtConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtNonConstant', [3], [
|
||||
new Benchmark('StringCharCodeAtNonConstant', true, false, 0,
|
||||
StringCharCodeAtNonConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtConstantInbounds', [3], [
|
||||
new Benchmark('StringCharCodeAtConstantInbounds', true, false, 0,
|
||||
StringCharCodeAtConstantInbounds),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCharCodeAtNonConstantInbounds', [3], [
|
||||
new Benchmark('StringCharCodeAtNonConstantInbounds', true, false, 0,
|
||||
StringCharCodeAtNonConstantInbounds),
|
||||
]);
|
||||
|
||||
const string = "qweruiplkjhgfdsazxccvbnm";
|
||||
const indices = [1, 13, 32, 100, "xx"];
|
||||
const indicesInbounds = [1, 7, 13, 17, "xx"];
|
||||
|
||||
function StringCharCodeAtConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indices[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtNonConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indices[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indicesInbounds[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCharCodeAtNonConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += string.charCodeAt(indicesInbounds[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtConstant', [3], [
|
||||
new Benchmark('StringCodePointAtConstant', true, false, 0,
|
||||
StringCodePointAtConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtNonConstant', [3], [
|
||||
new Benchmark('StringCodePointAtNonConstant', true, false, 0,
|
||||
StringCodePointAtNonConstant),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtConstantInbounds', [3], [
|
||||
new Benchmark('StringCodePointAtConstantInbounds', true, false, 0,
|
||||
StringCodePointAtConstantInbounds),
|
||||
]);
|
||||
|
||||
new BenchmarkSuite('StringCodePointAtNonConstantInbounds', [3], [
|
||||
new Benchmark('StringCodePointAtNonConstantInbounds', true, false, 0,
|
||||
StringCodePointAtNonConstantInbounds),
|
||||
]);
|
||||
|
||||
const unicode_string = "qweräϠ<C3A4>𝌆krefdäϠ<C3A4>𝌆ccäϠ<C3A4>𝌆";
|
||||
|
||||
function StringCodePointAtConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indices[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtNonConstant() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indices.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indices[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indicesInbounds[j] | 0);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
function StringCodePointAtNonConstantInbounds() {
|
||||
var sum = 0;
|
||||
|
||||
for (var j = 0; j < indicesInbounds.length - 1; ++j) {
|
||||
sum += unicode_string.codePointAt(indicesInbounds[j]);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
206
test/js-perf-test/Strings/string-substring.js
Normal file
206
test/js-perf-test/Strings/string-substring.js
Normal file
@ -0,0 +1,206 @@
|
||||
// Copyright 2017 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 benchy (f, name) {
|
||||
new BenchmarkSuite(name, [5], [
|
||||
new Benchmark(name, true, false, 0,
|
||||
f),
|
||||
]);
|
||||
}
|
||||
|
||||
const subjects = ['abcde', '123456', 'aqwsde', "nbvveqxu", "f03ks-120-3;jfkm;ajp3f", "sd-93u498thikefnow8y3-0rh1nalksfnwo8y3t19-3r8hoiefnw"];
|
||||
|
||||
// Drop first element.
|
||||
|
||||
function StringDropFirstSlice() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.slice(1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSlice, "StringDropFirstSlice");
|
||||
|
||||
function StringDropFirstSubstr() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substr(1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSubstr, "StringDropFirstSubstr");
|
||||
|
||||
function StringDropFirstSubstring() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substring(1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSubstring, "StringDropFirstSubstring");
|
||||
|
||||
|
||||
// Take first element.
|
||||
|
||||
function StringTakeFirstSlice() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.slice(0,1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeFirstSlice, "StringTakeFirstSlice");
|
||||
|
||||
function StringTakeFirstSubstr() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substr(0,1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeFirstSubstr, "StringTakeFirstSubstr");
|
||||
|
||||
function StringTakeFirstSubstring() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substring(0, 1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeFirstSubstring, "StringTakeFirstSubstring");
|
||||
|
||||
|
||||
// Drop last element.
|
||||
|
||||
function StringDropLastSlice() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.slice(0, -1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropLastSlice, "StringDropLastSlice");
|
||||
|
||||
function StringDropLastSubstr() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substr(0, s.length-1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropLastSubstr, "StringDropLastSubstr");
|
||||
|
||||
function StringDropLastSubstring() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substring(0, s.length-1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropLastSubstring, "StringDropLastSubstring");
|
||||
|
||||
|
||||
// Take last element.
|
||||
|
||||
function StringTakeLastSlice() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.slice(-1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeLastSlice, "StringTakeLastSlice");
|
||||
|
||||
function StringTakeLastSubstr() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substr(-1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeLastSubstr, "StringTakeLastSubstr");
|
||||
|
||||
function StringTakeLastSubstring() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substring(s.length-1, s.length);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringTakeLastSubstring, "StringTakeLastSubstring");
|
||||
|
||||
|
||||
// Drop first and last.
|
||||
|
||||
function StringDropFirstSlice() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.slice(1, -1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSlice, "StringDropFirstSlice");
|
||||
|
||||
function StringDropFirstSubstr() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j]
|
||||
sum += s.substr(1, s.length-2);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSubstr, "StringDropFirstSubstr");
|
||||
|
||||
function StringDropFirstSubstring() {
|
||||
var sum = "";
|
||||
|
||||
for (var j = 0; j < subjects.length; ++j) {
|
||||
let s = subjects[j];
|
||||
sum += s.substring(1, s.length-1);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
benchy(StringDropFirstSubstring, "StringDropFirstSubstring");
|
Loading…
Reference in New Issue
Block a user