1 package jdk.nashorn.internal.runtime.regexp.joni.bench; 2 3 import jdk.nashorn.internal.runtime.regexp.joni.Option; 4 import jdk.nashorn.internal.runtime.regexp.joni.Regex; 5 import jdk.nashorn.internal.runtime.regexp.joni.Syntax; 6 7 public abstract class AbstractBench { 8 protected void bench(String _reg, String _str, int warmup, int times) throws Exception { 9 char[] reg = _reg.toCharArray(); 10 char[] str = _str.toCharArray(); 11 12 Regex p = new Regex(reg,0,reg.length,Option.DEFAULT,Syntax.DEFAULT); 13 14 System.err.println("::: /" + _reg + "/ =~ \"" + _str + "\", " + warmup + " * " + times + " times"); 15 16 for(int j=0;j<warmup;j++) { 17 long before = System.currentTimeMillis(); 18 for(int i = 0; i < times; i++) { 19 p.matcher(str, 0, str.length).search(0, str.length, Option.NONE); 20 } 21 long time = System.currentTimeMillis() - before; 22 System.err.println(": " + time + "ms"); 23 } 24 } 25 26 protected void benchBestOf(String _reg, String _str, int warmup, int times) throws Exception { 27 char[] reg = _reg.toCharArray(); 28 char[] str = _str.toCharArray(); 29 30 Regex p = new Regex(reg,0,reg.length,Option.DEFAULT,Syntax.DEFAULT); 31 32 System.err.println("::: /" + _reg + "/ =~ \"" + _str + "\", " + warmup + " * " + times + " times"); 33 34 long best = Long.MAX_VALUE; 35 36 for(int j=0;j<warmup;j++) { 37 long before = System.currentTimeMillis(); 38 for(int i = 0; i < times; i++) { 39 p.matcher(str, 0, str.length).search(0, str.length, Option.NONE); 40 } 41 long time = System.currentTimeMillis() - before; 42 if(time < best) { 43 best = time; 44 } 45 System.err.print("."); 46 } 47 System.err.println(": " + best + "ms"); 48 } 49 }