Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.sample;
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- import java.lang.*;
- import java.io.*;
- import org.openjdk.jmh.annotations.*;
- import org.openjdk.jmh.infra.Blackhole;
- public class MyBenchmark {
- private static final Pattern pat = Pattern.compile( ".*a.*?b.*" );
- private static final String x = " ";
- private static final String text = " a b ";
- @Benchmark
- public boolean matcher_matches() throws java.lang.Exception {
- Matcher m = pat.matcher( text + x );
- return m.matches();
- }
- @Benchmark
- public boolean matcher_find() throws java.lang.Exception {
- Matcher m = pat.matcher( text + x );
- return m.find();
- }
- @Benchmark
- public String matcher_group() throws java.lang.Exception {
- Matcher m = pat.matcher( text + x );
- m.find();
- return m.group();
- }
- @Benchmark
- public int matcher_groupCount() throws java.lang.Exception {
- Matcher m = pat.matcher( text + x );
- m.find();
- return m.groupCount();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement