string-substring.js 4.09 KB
Newer Older
1 2 3 4
// 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.

5 6 7 8
const subjects = [
  'abcde', '123456', 'aqwsde', 'nbvveqxu', 'f03ks-120-3;jfkm;ajp3f',
  'sd-93u498thikefnow8y3-0rh1nalksfnwo8y3t19-3r8hoiefnw'
];
9 10 11 12 13 14 15 16 17 18 19 20 21

// Drop first element.

function StringDropFirstSlice() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.slice(1);
  }

  return sum;
}
22
createSuiteWithWarmup('StringDropFirstSlice', 5, StringDropFirstSlice);
23 24 25 26 27 28 29 30 31 32 33

function StringDropFirstSubstr() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substr(1);
  }

  return sum;
}
34
createSuiteWithWarmup('StringDropFirstSubstr', 5, StringDropFirstSubstr);
35 36 37 38 39 40 41 42 43 44 45

function StringDropFirstSubstring() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substring(1);
  }

  return sum;
}
46
createSuiteWithWarmup('StringDropFirstSubstring', 5, StringDropFirstSubstring);
47 48 49 50 51 52 53 54 55 56 57 58 59

// Take first element.

function StringTakeFirstSlice() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.slice(0,1);
  }

  return sum;
}
60
createSuiteWithWarmup('StringTakeFirstSlice', 5, StringTakeFirstSlice);
61 62 63 64 65 66 67 68 69 70 71

function StringTakeFirstSubstr() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substr(0,1);
  }

  return sum;
}
72
createSuiteWithWarmup('StringTakeFirstSubstr', 5, StringTakeFirstSubstr);
73 74 75 76 77 78 79 80 81 82 83

function StringTakeFirstSubstring() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substring(0, 1);
  }

  return sum;
}
84
createSuiteWithWarmup('StringTakeFirstSubstring', 5, StringTakeFirstSubstring);
85 86 87 88 89 90 91 92 93 94 95 96 97

// Drop last element.

function StringDropLastSlice() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.slice(0, -1);
  }

  return sum;
}
98
createSuiteWithWarmup('StringDropLastSlice', 5, StringDropLastSlice);
99 100 101 102 103 104 105 106 107 108 109

function StringDropLastSubstr() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substr(0, s.length-1);
  }

  return sum;
}
110
createSuiteWithWarmup('StringDropLastSubstr', 5, StringDropLastSubstr);
111 112 113 114 115 116 117 118 119 120 121

function StringDropLastSubstring() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substring(0, s.length-1);
  }

  return sum;
}
122
createSuiteWithWarmup('StringDropLastSubstring', 5, StringDropLastSubstring);
123 124 125 126 127 128 129 130 131 132 133 134 135

// Take last element.

function StringTakeLastSlice() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.slice(-1);
  }

  return sum;
}
136
createSuiteWithWarmup('StringTakeLastSlice', 5, StringTakeLastSlice);
137 138 139 140 141 142 143 144 145 146 147

function StringTakeLastSubstr() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substr(-1);
  }

  return sum;
}
148
createSuiteWithWarmup('StringTakeLastSubstr', 5, StringTakeLastSubstr);
149 150 151 152 153 154 155 156 157 158 159

function StringTakeLastSubstring() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substring(s.length-1, s.length);
  }

  return sum;
}
160
createSuiteWithWarmup('StringTakeLastSubstring', 5, StringTakeLastSubstring);
161 162 163 164 165 166 167 168 169 170 171 172 173

// Drop first and last.

function StringDropFirstSlice() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.slice(1, -1);
  }

  return sum;
}
174
createSuiteWithWarmup('StringDropFirstSlice', 5, StringDropFirstSlice);
175 176 177 178 179 180 181 182 183 184 185

function StringDropFirstSubstr() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j]
    sum += s.substr(1, s.length-2);
  }

  return sum;
}
186
createSuiteWithWarmup('StringDropFirstSubstr', 5, StringDropFirstSubstr);
187 188 189 190 191 192 193 194 195 196 197

function StringDropFirstSubstring() {
  var sum = "";

  for (var j = 0; j < subjects.length; ++j) {
    let s = subjects[j];
    sum += s.substring(1, s.length-1);
  }

  return sum;
}
198
createSuiteWithWarmup('StringDropFirstSubstring', 5, StringDropFirstSubstring);