[js-perf-test] Add micro-benchmark for StringAt functions
This benchmark checks comparison with StringAt functions against each other and and constants. The benchmarks will serve to measure the effect of an optimization that will omit the implicit String.fromCharCode in such cases. Bug: v8:7531 Change-Id: I171df92301516c96beb6a4ed86f1dec8d10e34f5 Reviewed-on: https://chromium-review.googlesource.com/957086 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Cr-Commit-Position: refs/heads/master@{#51839}
This commit is contained in:
parent
31ac0219a3
commit
5bc8daf6b4
@ -255,6 +255,22 @@
|
||||
{"name": "StringCodePointAtNonConstantInbounds"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringAtComparison",
|
||||
"main": "run.js",
|
||||
"resources": [ "string-stringat-comp.js" ],
|
||||
"test_flags": [ "string-stringat-comp" ],
|
||||
"results_regexp": "^%s\\-Strings\\(Score\\): (.+)$",
|
||||
"run_count": 1,
|
||||
"tests": [
|
||||
{"name": "charCodeAt_const"},
|
||||
{"name": "charCodeAt_both"},
|
||||
{"name": "charAt_const"},
|
||||
{"name": "charAt_never"},
|
||||
{"name": "charAt_both"},
|
||||
{"name": "stringIndex_const"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StringSubstring",
|
||||
"main": "run.js",
|
||||
|
50
test/js-perf-test/Strings/string-stringat-comp.js
Normal file
50
test/js-perf-test/Strings/string-stringat-comp.js
Normal file
@ -0,0 +1,50 @@
|
||||
// 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, [1], [
|
||||
new Benchmark(name, true, false, 0, f),
|
||||
]);
|
||||
}
|
||||
|
||||
const input = 'äϠ<C3A4>𝌆 Lorem ipsum test test';
|
||||
|
||||
function helper(fn) {
|
||||
var sum = 0;
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
sum += fn(input, i, i);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
function charCodeAt(str, i) {
|
||||
return str.charCodeAt(i) === 116;
|
||||
}
|
||||
|
||||
function charCodeAtBoth(str, i, j) {
|
||||
return str.charCodeAt(j) == str.charCodeAt(i);
|
||||
}
|
||||
|
||||
function charAt(str, i) {
|
||||
return 't' == str.charAt(i);
|
||||
}
|
||||
|
||||
function charAtNever(str, i) {
|
||||
return '𝌆' == str.charAt(i);
|
||||
}
|
||||
|
||||
function charAtBoth(str, i, j) {
|
||||
return str.charAt(j) == str.charAt(i);
|
||||
}
|
||||
|
||||
function stringIndex(str, i) {
|
||||
return str[i] === 't';
|
||||
}
|
||||
|
||||
benchy(() => helper(charCodeAt), "charCodeAt_const");
|
||||
benchy(() => helper(charCodeAtBoth), "charCodeAt_both");
|
||||
benchy(() => helper(charAt), "charAt_const");
|
||||
benchy(() => helper(charAtNever), "charAt_never");
|
||||
benchy(() => helper(charAtBoth), "charAt_both");
|
||||
benchy(() => helper(stringIndex), "stringIndex_const");
|
Loading…
Reference in New Issue
Block a user