blob: 1e0be73ce01b75f50ac503334167a4f9f2904409 [file] [log] [blame]
Andrew Top63c7ad42019-11-25 16:10:13 -08001// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5new BenchmarkSuite('StringCharCodeAtConstant', [3], [
6 new Benchmark('StringCharCodeAtConstant', true, false, 0,
7 StringCharCodeAtConstant),
8]);
9
10new BenchmarkSuite('StringCharCodeAtNonConstant', [3], [
11 new Benchmark('StringCharCodeAtNonConstant', true, false, 0,
12 StringCharCodeAtNonConstant),
13]);
14
15new BenchmarkSuite('StringCharCodeAtConstantInbounds', [3], [
16 new Benchmark('StringCharCodeAtConstantInbounds', true, false, 0,
17 StringCharCodeAtConstantInbounds),
18]);
19
20new BenchmarkSuite('StringCharCodeAtNonConstantInbounds', [3], [
21 new Benchmark('StringCharCodeAtNonConstantInbounds', true, false, 0,
22 StringCharCodeAtNonConstantInbounds),
23]);
24
25const string = "qweruiplkjhgfdsazxccvbnm";
26const indices = [1, 13, 32, 100, "xx"];
27const indicesInbounds = [1, 7, 13, 17, "xx"];
28
29function StringCharCodeAtConstant() {
30 var sum = 0;
31
32 for (var j = 0; j < indices.length - 1; ++j) {
33 sum += string.charCodeAt(indices[j] | 0);
34 }
35
36 return sum;
37}
38
39function StringCharCodeAtNonConstant() {
40 var sum = 0;
41
42 for (var j = 0; j < indices.length - 1; ++j) {
43 sum += string.charCodeAt(indices[j]);
44 }
45
46 return sum;
47}
48
49function StringCharCodeAtConstantInbounds() {
50 var sum = 0;
51
52 for (var j = 0; j < indicesInbounds.length - 1; ++j) {
53 sum += string.charCodeAt(indicesInbounds[j] | 0);
54 }
55
56 return sum;
57}
58
59function StringCharCodeAtNonConstantInbounds() {
60 var sum = 0;
61
62 for (var j = 0; j < indicesInbounds.length - 1; ++j) {
63 sum += string.charCodeAt(indicesInbounds[j]);
64 }
65
66 return sum;
67}
68
69new BenchmarkSuite('StringCodePointAtConstant', [3], [
70 new Benchmark('StringCodePointAtConstant', true, false, 0,
71 StringCodePointAtConstant),
72]);
73
74new BenchmarkSuite('StringCodePointAtNonConstant', [3], [
75 new Benchmark('StringCodePointAtNonConstant', true, false, 0,
76 StringCodePointAtNonConstant),
77]);
78
79new BenchmarkSuite('StringCodePointAtConstantInbounds', [3], [
80 new Benchmark('StringCodePointAtConstantInbounds', true, false, 0,
81 StringCodePointAtConstantInbounds),
82]);
83
84new BenchmarkSuite('StringCodePointAtNonConstantInbounds', [3], [
85 new Benchmark('StringCodePointAtNonConstantInbounds', true, false, 0,
86 StringCodePointAtNonConstantInbounds),
87]);
88
89const unicode_string = "qweräϠ�𝌆krefdäϠ�𝌆ccäϠ�𝌆";
90
91function StringCodePointAtConstant() {
92 var sum = 0;
93
94 for (var j = 0; j < indices.length - 1; ++j) {
95 sum += unicode_string.codePointAt(indices[j] | 0);
96 }
97
98 return sum;
99}
100
101function StringCodePointAtNonConstant() {
102 var sum = 0;
103
104 for (var j = 0; j < indices.length - 1; ++j) {
105 sum += unicode_string.codePointAt(indices[j]);
106 }
107
108 return sum;
109}
110
111function StringCodePointAtConstantInbounds() {
112 var sum = 0;
113
114 for (var j = 0; j < indicesInbounds.length - 1; ++j) {
115 sum += unicode_string.codePointAt(indicesInbounds[j] | 0);
116 }
117
118 return sum;
119}
120
121function StringCodePointAtNonConstantInbounds() {
122 var sum = 0;
123
124 for (var j = 0; j < indicesInbounds.length - 1; ++j) {
125 sum += unicode_string.codePointAt(indicesInbounds[j]);
126 }
127
128 return sum;
129}