Commit 6d36bae4 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[js-perf-tests] Improve string benchmarks

Add inbounds benchmark for String.p.charCodeAt
and add in and out of bounds benchmarks for
String.p.codePointAt.

Bug: v8:7092, v8:7326, chromium:806758
Change-Id: I48065627bd79d8fb24e55b2f6dce590e7adbbd6e
Reviewed-on: https://chromium-review.googlesource.com/891858Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50942}
parent fb08052c
......@@ -35,20 +35,31 @@ function StringIndexOfNonConstant() {
return sum;
}
new BenchmarkSuite('StringCharCodeAtConstant', [3], [
new Benchmark('StringIndexOfConstant', true, false, 0,
StringCharCodeAtConstant),
new BenchmarkSuite('StringCharCodeAtConstantWithOutOfBounds', [3], [
new Benchmark('StringCharCodeAtConstantWithOutOfBounds', true, false, 0,
StringCharCodeAtConstantWithOutOfBounds),
]);
new BenchmarkSuite('StringCharCodeAtNonConstant', [3], [
new Benchmark('StringIndexOfNonConstant', true, false, 0,
StringCharCodeAtNonConstant),
new BenchmarkSuite('StringCharCodeAtNonConstantWithOutOfBounds', [3], [
new Benchmark('StringCharCodeAtNonConstantWithOutOfBounds', true, false, 0,
StringCharCodeAtNonConstantWithOutOfBounds),
]);
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() {
function StringCharCodeAtConstantWithOutOfBounds() {
var sum = 0;
for (var j = 0; j < indices.length - 1; ++j) {
......@@ -58,7 +69,7 @@ function StringCharCodeAtConstant() {
return sum;
}
function StringCharCodeAtNonConstant() {
function StringCharCodeAtNonConstantWithOutOfBounds() {
var sum = 0;
for (var j = 0; j < indices.length - 1; ++j) {
......@@ -67,3 +78,85 @@ function StringCharCodeAtNonConstant() {
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('StringCodePointAtConstantWithOutOfBounds', [3], [
new Benchmark('StringCodePointAtConstantWithOutOfBounds', true, false, 0,
StringCodePointAtConstantWithOutOfBounds),
]);
new BenchmarkSuite('StringCodePointAtNonConstantWithOutOfBounds', [3], [
new Benchmark('StringCodePointAtNonConstantWithOutOfBounds', true, false, 0,
StringCodePointAtNonConstantWithOutOfBounds),
]);
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äϠ�𝌆krefdäϠ�𝌆ccäϠ�𝌆";
function StringCodePointAtConstantWithOutOfBounds() {
var sum = 0;
for (var j = 0; j < indices.length - 1; ++j) {
sum += unicode_string.codePointAt(indices[j] | 0);
}
return sum;
}
function StringCodePointAtNonConstantWithOutOfBounds() {
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;
}
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