Guest User

Untitled

a guest
Aug 9th, 2016
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.sample;
  2.  
  3. import java.util.regex.Pattern;
  4. import java.util.regex.Matcher;
  5. import java.lang.*;
  6. import java.io.*;
  7. import org.openjdk.jmh.annotations.*;
  8. import org.openjdk.jmh.infra.Blackhole;
  9.  
  10.  
  11. public class MyBenchmark {
  12.  
  13.     private static final Pattern pat = Pattern.compile( ".*a.*?b.*" );
  14.     private static final String x = " ";
  15.     private static final String text = "             a                      b                     ";
  16.  
  17.     @Benchmark
  18.     public boolean matcher_matches() throws java.lang.Exception {
  19.         Matcher m = pat.matcher( text + x );
  20.         return m.matches();
  21.     }
  22.  
  23.     @Benchmark
  24.     public boolean matcher_find() throws java.lang.Exception {
  25.         Matcher m = pat.matcher( text + x );
  26.         return m.find();
  27.     }
  28.  
  29.     @Benchmark
  30.     public String matcher_group() throws java.lang.Exception {
  31.         Matcher m = pat.matcher( text + x );
  32.         m.find();
  33.         return m.group();
  34.     }
  35.  
  36.     @Benchmark
  37.     public int matcher_groupCount() throws java.lang.Exception {
  38.         Matcher m = pat.matcher( text + x );
  39.         m.find();
  40.         return m.groupCount();
  41.     }
  42. }
RAW Paste Data