v8/test/js-perf-test/Strings/string-indexof.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
879 B
JavaScript
Raw Normal View 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.
new BenchmarkSuite('StringIndexOfConstant', [1000], [
new Benchmark('StringIndexOfConstant', true, false, 0,
StringIndexOfConstant),
]);
new BenchmarkSuite('StringIndexOfNonConstant', [1000], [
new Benchmark('StringIndexOfNonConstant', true, false, 0,
StringIndexOfNonConstant),
]);
const N = 10 ** 6;
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;
}