v8/test/js-perf-test/Strings/string-startsendswith-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

48 lines
1.3 KiB
JavaScript

// Copyright 2018 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.
function createSuiteWithWarmup( name, count, fn) {
new BenchmarkSuite(name, [count], [
new Benchmark(name, true, false, 0, fn),
]);
}
const inputs = [
'I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\u2603\uD83D\uDCA9\uFFFD',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Integer eu augue suscipit, accumsan ipsum nec, sagittis sem.',
'In vitae pellentesque dolor. Curabitur leo nunc, luctus vitae',
'risus eget, fermentum hendrerit justo.',
];
const first = 'I';
function helper(fn) {
let sum = 0;
for (const input of inputs) {
sum += fn(input);
}
return sum;
}
function startsWith(string) {
return string.startsWith(first);
}
function startsIndex(string) {
return string[0] === first;
}
function endsWith(string) {
return string.endsWith(first);
}
function endsIndex(string) {
return string[string.length - 1] === first;
}
createSuiteWithWarmup('startsWith', 1, () => helper(startsWith));
createSuiteWithWarmup('startsIndex', 1, () => helper(startsIndex));
createSuiteWithWarmup('endsWith', 1, () => helper(endsWith));
createSuiteWithWarmup('endsIndex', 1, () => helper(endsIndex));