Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 1 | // 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 | |
| 5 | new BenchmarkSuite('StringCharCodeAtConstant', [3], [ |
| 6 | new Benchmark('StringCharCodeAtConstant', true, false, 0, |
| 7 | StringCharCodeAtConstant), |
| 8 | ]); |
| 9 | |
| 10 | new BenchmarkSuite('StringCharCodeAtNonConstant', [3], [ |
| 11 | new Benchmark('StringCharCodeAtNonConstant', true, false, 0, |
| 12 | StringCharCodeAtNonConstant), |
| 13 | ]); |
| 14 | |
| 15 | new BenchmarkSuite('StringCharCodeAtConstantInbounds', [3], [ |
| 16 | new Benchmark('StringCharCodeAtConstantInbounds', true, false, 0, |
| 17 | StringCharCodeAtConstantInbounds), |
| 18 | ]); |
| 19 | |
| 20 | new BenchmarkSuite('StringCharCodeAtNonConstantInbounds', [3], [ |
| 21 | new Benchmark('StringCharCodeAtNonConstantInbounds', true, false, 0, |
| 22 | StringCharCodeAtNonConstantInbounds), |
| 23 | ]); |
| 24 | |
| 25 | const string = "qweruiplkjhgfdsazxccvbnm"; |
| 26 | const indices = [1, 13, 32, 100, "xx"]; |
| 27 | const indicesInbounds = [1, 7, 13, 17, "xx"]; |
| 28 | |
| 29 | function 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 | |
| 39 | function 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 | |
| 49 | function 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 | |
| 59 | function 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 | |
| 69 | new BenchmarkSuite('StringCodePointAtConstant', [3], [ |
| 70 | new Benchmark('StringCodePointAtConstant', true, false, 0, |
| 71 | StringCodePointAtConstant), |
| 72 | ]); |
| 73 | |
| 74 | new BenchmarkSuite('StringCodePointAtNonConstant', [3], [ |
| 75 | new Benchmark('StringCodePointAtNonConstant', true, false, 0, |
| 76 | StringCodePointAtNonConstant), |
| 77 | ]); |
| 78 | |
| 79 | new BenchmarkSuite('StringCodePointAtConstantInbounds', [3], [ |
| 80 | new Benchmark('StringCodePointAtConstantInbounds', true, false, 0, |
| 81 | StringCodePointAtConstantInbounds), |
| 82 | ]); |
| 83 | |
| 84 | new BenchmarkSuite('StringCodePointAtNonConstantInbounds', [3], [ |
| 85 | new Benchmark('StringCodePointAtNonConstantInbounds', true, false, 0, |
| 86 | StringCodePointAtNonConstantInbounds), |
| 87 | ]); |
| 88 | |
| 89 | const unicode_string = "qweräϠ�𝌆krefdäϠ�𝌆ccäϠ�𝌆"; |
| 90 | |
| 91 | function 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 | |
| 101 | function 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 | |
| 111 | function 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 | |
| 121 | function 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 | } |