summaryrefslogtreecommitdiff
path: root/deps/v8/test/js-perf-test/Strings/string-stringat.js
blob: 1e0be73ce01b75f50ac503334167a4f9f2904409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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äϠ�𝌆krefdäϠ�𝌆ccäϠ�𝌆";

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;
}