OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 load("base.js"); |
| 6 |
| 7 var str; |
| 8 var re; |
| 9 |
| 10 function StringReplace1() { |
| 11 str.replace(re, ""); |
| 12 } |
| 13 |
| 14 function StringReplace2() { |
| 15 str.replace(re, "xyz"); |
| 16 } |
| 17 |
| 18 function StringReplace3() { |
| 19 str.replace(re, "x$1yz"); |
| 20 } |
| 21 |
| 22 function FunctionReplace1() { |
| 23 str.replace(re, String); |
| 24 } |
| 25 |
| 26 function Replace1Setup() { |
| 27 re = /[Cz]/; |
| 28 str = createHaystack(); |
| 29 } |
| 30 |
| 31 function Replace2Setup() { |
| 32 re = /[Cz]/g; |
| 33 str = createHaystack(); |
| 34 } |
| 35 |
| 36 function Replace3Setup() { |
| 37 re = /([Cz])/; |
| 38 str = createHaystack(); |
| 39 } |
| 40 |
| 41 function Replace4Setup() { |
| 42 re = /([Cz])/g; |
| 43 str = createHaystack(); |
| 44 } |
| 45 |
| 46 var benchmarks = [ [ StringReplace1, Replace1Setup], |
| 47 [ StringReplace1, Replace2Setup], |
| 48 [ StringReplace2, Replace1Setup], |
| 49 [ StringReplace2, Replace2Setup], |
| 50 [ StringReplace3, Replace3Setup], |
| 51 [ StringReplace3, Replace4Setup], |
| 52 [ FunctionReplace1, Replace3Setup], |
| 53 [ FunctionReplace1, Replace4Setup], |
| 54 ]; |
OLD | NEW |