v8/test/js-perf-test/Strings/string-indexof.js
Sigurd Schneider 4dd446ab47 [js-perf-tests] Add substring perf tests
This CL also reorganizes the Strings test suite

Bug: v8:7340
Change-Id: I54d4d76a16c362e38ebfc9719ac8cb1a490ef3cc
Reviewed-on: https://chromium-review.googlesource.com/941122
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51631}
2018-02-28 13:03:57 +00:00

37 lines
854 B
JavaScript

// 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('StringIndexOfConstant', [5], [
new Benchmark('StringIndexOfConstant', true, false, 0,
StringIndexOfConstant),
]);
new BenchmarkSuite('StringIndexOfNonConstant', [5], [
new Benchmark('StringIndexOfNonConstant', true, false, 0,
StringIndexOfNonConstant),
]);
const subject = "aaaaaaaaaaaaaaaab";
const searches = ['a', 'b', 'c'];
function StringIndexOfConstant() {
var sum = 0;
for (var j = 0; j < searches.length; ++j) {
sum += subject.indexOf("" + searches[j]);
}
return sum;
}
function StringIndexOfNonConstant() {
var sum = 0;
for (var j = 0; j < searches.length; ++j) {
sum += subject.indexOf(searches[j]);
}
return sum;
}