v8/test/js-perf-test/Strings/string-stringat-comp.js
Camillo Bruni f728d6984d [js-perf-test] Consistently use createSuite in all benchmarks
Change-Id: I7bf0144bacd0572a42b98d0a0f19df3daf63128b
Bug: chromium:840785
Reviewed-on: https://chromium-review.googlesource.com/1051240
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53418}
2018-05-29 15:06:48 +00:00

45 lines
1.2 KiB
JavaScript
Raw Blame History

// 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.
const input = 'äϠ<C3A4>𝌆 Lorem ipsum test test';
function helper(fn) {
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += fn(input, i, i);
}
return sum;
}
function charCodeAt(str, i) {
return str.charCodeAt(i) === 116;
}
function charCodeAtBoth(str, i, j) {
return str.charCodeAt(j) == str.charCodeAt(i);
}
function charAt(str, i) {
return 't' == str.charAt(i);
}
function charAtNever(str, i) {
return '𝌆' == str.charAt(i);
}
function charAtBoth(str, i, j) {
return str.charAt(j) == str.charAt(i);
}
function stringIndex(str, i) {
return str[i] === 't';
}
createSuiteWithWarmup('charCodeAt_const', 1, () => helper(charCodeAt));
createSuiteWithWarmup('charCodeAt_both', 1, () => helper(charCodeAtBoth));
createSuiteWithWarmup('charAt_const', 1, () => helper(charAt));
createSuiteWithWarmup('charAt_never', 1, () => helper(charAtNever));
createSuiteWithWarmup('charAt_both', 1, () => helper(charAtBoth));
createSuiteWithWarmup('stringIndex_const', 1, () => helper(stringIndex));