Commit b034b715 authored by jgruber's avatar jgruber Committed by Commit bot

[js-perf-test] Add RegExp microbenchmarks

This adds microbenchmarks for:

* the RegExp constructor,
* flag accessors,
* and RegExp functions: exec, @@match, @@search, test, @@split, @@replace.

Each benchmark is further split to measure fast and slow paths.

BUG=v8:5339

Review-Url: https://codereview.chromium.org/2521263003
Cr-Commit-Position: refs/heads/master@{#41285}
parent daedefd3
{
"name": "RegExp",
"run_count": 3,
"run_count_arm": 1,
"run_count_arm64": 1,
"timeout": 120,
"units": "score",
"total": true,
"resources": ["base.js"],
"tests": [
{
"name": "RegExp",
"path": ["RegExp"],
"main": "run.js",
"resources": [
"base_ctor.js",
"base_exec.js",
"base_flags.js",
"base_match.js",
"base_replace.js",
"base_search.js",
"base_split.js",
"base_test.js",
"base.js",
"ctor.js",
"exec.js",
"flags.js",
"match.js",
"replace.js",
"search.js",
"split.js",
"test.js",
"slow_exec.js",
"slow_flags.js",
"slow_match.js",
"slow_replace.js",
"slow_search.js",
"slow_split.js",
"slow_test.js",
],
"results_regexp": "^%s\\-RegExp\\(Score\\): (.+)$",
"tests": [
{"name": "Ctor"},
{"name": "Exec"},
{"name": "Flags"},
{"name": "Match"},
{"name": "Replace"},
{"name": "Search"},
{"name": "Split"},
{"name": "Test"},
{"name": "SlowExec"},
{"name": "SlowFlags"},
{"name": "SlowMatch"},
{"name": "SlowReplace"},
{"name": "SlowSearch"},
{"name": "SlowSplit"},
{"name": "SlowTest"},
]
},
]
}
{
"name": "RegExpTests",
"run_count": 5,
"run_count_android_arm": 3,
"run_count_android_arm64": 3,
"timeout": 120,
"units": "score",
"total": true,
"resources": ["base.js"],
"tests": [
{
"name": "RegExp",
"path": ["."],
"main": "run.js",
"resources": [
"base_ctor.js",
"base_exec.js",
"base_flags.js",
"base_match.js",
"base_replace.js",
"base_search.js",
"base_split.js",
"base_test.js",
"base.js",
"ctor.js",
"exec.js",
"flags.js",
"match.js",
"replace.js",
"search.js",
"split.js",
"test.js",
"slow_exec.js",
"slow_flags.js",
"slow_match.js",
"slow_replace.js",
"slow_search.js",
"slow_split.js",
"slow_test.js",
],
"results_regexp": "^%s\\-RegExp\\(Score\\): (.+)$",
"tests": [
{"name": "Ctor"},
{"name": "Exec"},
{"name": "Flags"},
{"name": "Match"},
{"name": "Replace"},
{"name": "Search"},
{"name": "Split"},
{"name": "Test"},
{"name": "SlowExec"},
{"name": "SlowFlags"},
{"name": "SlowMatch"},
{"name": "SlowReplace"},
{"name": "SlowSearch"},
{"name": "SlowSplit"},
{"name": "SlowTest"},
]
}
]
}
// Copyright 2016 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 benchName(bench, setup) {
var name = bench.name;
if (setup) name += "/" + setup.name;
}
function slowBenchName(bench, setup) {
return benchName(bench, setup) + " (Slow)";
}
function slow(setupFunction) {
return () => {
setupFunction();
// Trigger RegExp slow paths.
const regExpExec = re.exec;
re.exec = (str) => regExpExec.call(re, str);
};
}
function createHaystack() {
let s = "abCdefgz";
for (let i = 0; i < 3; i++) s += s;
return s;
}
function createBenchmarkSuite(name) {
return new BenchmarkSuite(
name, [1000],
benchmarks.map(([bench, setup]) =>
new Benchmark(benchName(bench, setup), false, false, 0, bench,
setup)));
}
function createSlowBenchmarkSuite(name) {
return new BenchmarkSuite(
"Slow" + name, [1000],
benchmarks.map(([bench, setup]) =>
new Benchmark(slowBenchName(bench, setup), false, false, 0, bench,
slow(setup))));
}
// Copyright 2016 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 SimpleCtor() {
new RegExp("[Cz]");
}
function FlagsCtor() {
new RegExp("[Cz]", "guiym");
}
function SimpleCtorWithoutNew() {
RegExp("[Cz]");
}
function FlagsCtorWithoutNew() {
RegExp("[Cz]", "guiym");
}
function CtorWithRegExpPattern() {
new RegExp(/[Cz]/);
}
function CtorWithRegExpPatternAndFlags() {
new RegExp(/[Cz]/, "guiym");
}
function CtorWithRegExpSubclassPattern() {
class SubRegExp extends RegExp {
get source() { return "[Cz]"; }
get flags() { return "guiym"; }
}
new RegExp(new SubRegExp(/[Cz]/));
}
function CtorWithUndefinedPattern() {
new RegExp();
}
function CtorWithFlagsAndUndefinedPattern() {
new RegExp(undefined, "guiym");
}
var benchmarks = [ [SimpleCtor, undefined],
[FlagsCtor, undefined],
[SimpleCtorWithoutNew, undefined],
[FlagsCtorWithoutNew, undefined],
[CtorWithRegExpPattern, undefined],
[CtorWithRegExpPatternAndFlags, undefined],
[CtorWithRegExpSubclassPattern, undefined],
[CtorWithUndefinedPattern, undefined],
[CtorWithFlagsAndUndefinedPattern, undefined],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function Exec() {
re.exec(str);
}
function Exec1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Exec2Setup() {
re = /[Cz]/g;
str = createHaystack();
}
function Exec3Setup() {
re = /([Cz])/y;
str = createHaystack();
}
function Exec4Setup() {
re = /[cZ]/;
str = createHaystack();
}
function Exec5Setup() {
re = /[cZ]/g;
str = createHaystack();
}
function Exec6Setup() {
re = /([cZ])/y;
str = createHaystack();
}
function Exec7Setup() {
re = /[Cz]/gy;
re.lastIndex = 2 ** 32;
str = createHaystack();
}
var benchmarks = [ [Exec, Exec1Setup],
[Exec, Exec2Setup],
[Exec, Exec3Setup],
[Exec, Exec4Setup],
[Exec, Exec5Setup],
[Exec, Exec6Setup],
[Exec, Exec7Setup],
];
// Copyright 2016 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.
var re;
function Global() {
var g = re.global;
}
function Flags() {
var f = re.flags;
}
function Setup() {
re = /[Cz]/giym;
}
var benchmarks = [ [Global, Setup],
[Flags, Setup],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function SimpleMatch() {
str.match(re);
}
function Match1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Match2Setup() {
re = /[Cz]/g;
str = createHaystack();
}
function Match3Setup() {
re = /[cZ]/; // Not found.
str = createHaystack();
}
var benchmarks = [ [SimpleMatch, Match1Setup],
[SimpleMatch, Match2Setup],
[SimpleMatch, Match3Setup],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function StringReplace1() {
str.replace(re, "");
}
function StringReplace2() {
str.replace(re, "xyz");
}
function StringReplace3() {
str.replace(re, "x$1yz");
}
function FunctionReplace1() {
str.replace(re, String);
}
function Replace1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Replace2Setup() {
re = /[Cz]/g;
str = createHaystack();
}
function Replace3Setup() {
re = /([Cz])/;
str = createHaystack();
}
function Replace4Setup() {
re = /([Cz])/g;
str = createHaystack();
}
var benchmarks = [ [ StringReplace1, Replace1Setup],
[ StringReplace1, Replace2Setup],
[ StringReplace2, Replace1Setup],
[ StringReplace2, Replace2Setup],
[ StringReplace3, Replace3Setup],
[ StringReplace3, Replace4Setup],
[ FunctionReplace1, Replace3Setup],
[ FunctionReplace1, Replace4Setup],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function SimpleSearch() {
str.search(re);
}
function Search1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Search2Setup() {
re = /[Cz]/;
re.lastIndex = 42; // Force lastIndex restoration.
str = createHaystack();
}
function Search3Setup() {
re = /[cZ]/; // Not found.
str = createHaystack();
}
var benchmarks = [ [SimpleSearch, Search1Setup],
[SimpleSearch, Search2Setup],
[SimpleSearch, Search3Setup],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function SimpleSplit() {
str.split(re);
}
function Split1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Split2Setup() {
re = /[Cz]/u;
str = createHaystack();
}
function Split3Setup() {
re = /[Cz]/y;
str = createHaystack();
}
function Split4Setup() {
re = /[Cz]/uy;
str = createHaystack();
}
function Split5Setup() {
re = /[Cz]/;
str = "";
}
function Split6Setup() {
re = /[cZ]/; // No match.
str = createHaystack();
}
function Split7Setup() {
re = /[A-Za-z\u0080-\u00FF ]/;
str = "hipopótamo maçã pólen ñ poção água língüa";
}
var benchmarks = [ [SimpleSplit, Split1Setup],
[SimpleSplit, Split2Setup],
[SimpleSplit, Split3Setup],
[SimpleSplit, Split4Setup],
[SimpleSplit, Split5Setup],
[SimpleSplit, Split6Setup],
[SimpleSplit, Split7Setup],
];
// Copyright 2016 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.
load("base.js");
var str;
var re;
function SimpleTest() {
re.test(str);
}
function Test1Setup() {
re = /[Cz]/;
str = createHaystack();
}
function Test2Setup() {
re = /[cZ]/; // Not found.
str = createHaystack();
}
var benchmarks = [ [SimpleTest, Test1Setup],
[SimpleTest, Test2Setup],
];
// Copyright 2016 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.
load("base.js");
load("base_ctor.js");
createBenchmarkSuite("Ctor");
// Copyright 2016 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.
load("base.js");
load("base_exec.js");
createBenchmarkSuite("Exec");
// Copyright 2016 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.
load("base.js");
load("base_flags.js");
createBenchmarkSuite("Flags");
// Copyright 2016 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.
load("base.js");
load("base_match.js");
createBenchmarkSuite("Match");
// Copyright 2016 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.
load("base.js");
load("base_replace.js");
createBenchmarkSuite("Replace");
// Copyright 2016 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.
load('../base.js');
load('ctor.js');
load('exec.js');
load('flags.js');
load('match.js');
load('replace.js');
load('search.js');
load('split.js');
load('test.js');
load('slow_exec.js');
load('slow_flags.js');
load('slow_match.js');
load('slow_replace.js');
load('slow_search.js');
load('slow_split.js');
load('slow_test.js');
var success = true;
function PrintResult(name, result) {
print(name + '-RegExp(Score): ' + result);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });
// Copyright 2016 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.
load("base.js");
load("base_search.js");
createBenchmarkSuite("Search");
// Copyright 2016 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.
load("base.js");
load("base_exec.js");
createSlowBenchmarkSuite("Exec");
// Copyright 2016 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.
load("base.js");
load("base_flags.js");
createSlowBenchmarkSuite("Flags");
// Copyright 2016 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.
load("base.js");
load("base_match.js");
createSlowBenchmarkSuite("Match");
// Copyright 2016 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.
load("base.js");
load("base_replace.js");
createSlowBenchmarkSuite("Replace");
// Copyright 2016 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.
load("base.js");
load("base_search.js");
createSlowBenchmarkSuite("Search");
// Copyright 2016 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.
load("base.js");
load("base_split.js");
createSlowBenchmarkSuite("Split");
// Copyright 2016 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.
load("base.js");
load("base_test.js");
createSlowBenchmarkSuite("Test");
// Copyright 2016 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.
load("base.js");
load("base_split.js");
createBenchmarkSuite("Split");
// Copyright 2016 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.
load("base.js");
load("base_test.js");
createBenchmarkSuite("Test");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment