aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/js-perf-test/RegExp/base_replace.js
blob: eae66d6102ad4d874bc8a4e0cb6f551074fd5afd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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],
                 ];