2014-10-21 11:05:32 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2018-02-28 11:38:57 +00:00
|
|
|
new BenchmarkSuite('StringRepeat', [10], [
|
2014-10-21 11:05:32 +00:00
|
|
|
new Benchmark('StringRepeat', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
Repeat, RepeatSetup, RepeatTearDown),
|
|
|
|
]);
|
|
|
|
|
|
|
|
new BenchmarkSuite('StringStartsWith', [10], [
|
2014-10-21 11:05:32 +00:00
|
|
|
new Benchmark('StringStartsWith', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
StartsWith, WithSetup, WithTearDown),
|
|
|
|
]);
|
|
|
|
|
|
|
|
new BenchmarkSuite('StringEndsWith', [10], [
|
2014-10-21 11:05:32 +00:00
|
|
|
new Benchmark('StringEndsWith', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
EndsWith, WithSetup, WithTearDown),
|
|
|
|
]);
|
|
|
|
|
|
|
|
new BenchmarkSuite('StringIncludes', [10], [
|
2014-11-20 19:19:34 +00:00
|
|
|
new Benchmark('StringIncludes', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
Includes, IncludesSetup, WithTearDown),
|
|
|
|
]);
|
|
|
|
|
|
|
|
new BenchmarkSuite('StringFromCodePoint', [10000], [
|
2014-10-22 11:08:42 +00:00
|
|
|
new Benchmark('StringFromCodePoint', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
FromCodePoint, FromCodePointSetup, FromCodePointTearDown),
|
|
|
|
]);
|
|
|
|
|
|
|
|
new BenchmarkSuite('StringCodePointAt', [1000], [
|
2014-10-22 11:08:42 +00:00
|
|
|
new Benchmark('StringCodePointAt', false, false, 0,
|
2018-02-28 11:38:57 +00:00
|
|
|
CodePointAt, CodePointAtSetup, CodePointAtTearDown),
|
2014-10-21 11:05:32 +00:00
|
|
|
]);
|
|
|
|
|
2018-03-01 12:48:23 +00:00
|
|
|
new BenchmarkSuite('StringCodePointAtSum', [100000], [
|
|
|
|
new Benchmark('StringCodePointAtSum', false, true, 3,
|
|
|
|
CodePointAtSum, CodePointAtSumSetup),
|
|
|
|
]);
|
|
|
|
|
2014-10-21 11:05:32 +00:00
|
|
|
|
|
|
|
var result;
|
|
|
|
|
|
|
|
var stringRepeatSource = "abc";
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function RepeatSetup() {
|
2014-10-21 11:05:32 +00:00
|
|
|
result = undefined;
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function Repeat() {
|
2014-10-21 11:05:32 +00:00
|
|
|
result = stringRepeatSource.repeat(500);
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function RepeatTearDown() {
|
2014-10-21 11:05:32 +00:00
|
|
|
var expected = "";
|
2018-02-28 11:38:57 +00:00
|
|
|
for (var i = 0; i < 1000; i++) {
|
2014-10-21 11:05:32 +00:00
|
|
|
expected += stringRepeatSource;
|
|
|
|
}
|
|
|
|
return result === expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var str;
|
|
|
|
var substr;
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function WithSetup() {
|
2014-10-21 11:05:32 +00:00
|
|
|
str = "abc".repeat(500);
|
|
|
|
substr = "abc".repeat(200);
|
|
|
|
result = undefined;
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function WithTearDown() {
|
2014-10-21 11:05:32 +00:00
|
|
|
return !!result;
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function StartsWith() {
|
2014-10-21 11:05:32 +00:00
|
|
|
result = str.startsWith(substr);
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:08:42 +00:00
|
|
|
function EndsWith() {
|
2014-10-21 11:05:32 +00:00
|
|
|
result = str.endsWith(substr);
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:19:34 +00:00
|
|
|
function IncludesSetup() {
|
2014-10-21 11:05:32 +00:00
|
|
|
str = "def".repeat(100) + "abc".repeat(100) + "qqq".repeat(100);
|
|
|
|
substr = "abc".repeat(100);
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:19:34 +00:00
|
|
|
function Includes() {
|
|
|
|
result = str.includes(substr);
|
2014-10-21 11:05:32 +00:00
|
|
|
}
|
2014-10-22 11:08:42 +00:00
|
|
|
|
|
|
|
var MAX_CODE_POINT = 0xFFFFF;
|
2018-02-28 11:38:57 +00:00
|
|
|
const K = 1024;
|
2014-10-22 11:08:42 +00:00
|
|
|
|
|
|
|
function FromCodePointSetup() {
|
2018-02-28 11:38:57 +00:00
|
|
|
result = new Array((MAX_CODE_POINT + 1) / K);
|
2014-10-22 11:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function FromCodePoint() {
|
2018-02-28 11:38:57 +00:00
|
|
|
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
2014-10-22 11:08:42 +00:00
|
|
|
result[i] = String.fromCodePoint(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FromCodePointTearDown() {
|
2018-02-28 11:38:57 +00:00
|
|
|
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
2014-10-22 11:08:42 +00:00
|
|
|
if (i !== result[i].codePointAt(0)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var allCodePoints;
|
|
|
|
|
|
|
|
function CodePointAtSetup() {
|
2018-02-28 11:38:57 +00:00
|
|
|
allCodePoints = new Array((MAX_CODE_POINT + 1) / K);
|
|
|
|
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
2014-10-22 11:08:42 +00:00
|
|
|
allCodePoints = String.fromCodePoint(i);
|
|
|
|
}
|
|
|
|
result = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CodePointAt() {
|
|
|
|
result = 0;
|
2018-02-28 11:38:57 +00:00
|
|
|
for (var i = 0; i <= MAX_CODE_POINT; i += K) {
|
2014-10-22 11:08:42 +00:00
|
|
|
result += allCodePoints.codePointAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function CodePointAtTearDown() {
|
2018-02-28 11:38:57 +00:00
|
|
|
return result === (MAX_CODE_POINT / K) * ((MAX_CODE_POINT / K) + 1) / 2;
|
2014-10-22 11:08:42 +00:00
|
|
|
}
|
2018-03-01 12:48:23 +00:00
|
|
|
|
|
|
|
var payload;
|
|
|
|
|
|
|
|
function CodePointAtSumSetup() {
|
|
|
|
payload = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
for(var j = 0; j < 16; ++j) payload += payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CodePointAtSum() {
|
|
|
|
var c = 0;
|
|
|
|
for(j=payload.length-1; j >=0; --j) c+=payload.charCodeAt(j);
|
|
|
|
return c;
|
|
|
|
}
|