Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.operator.scalar;
 
 
 
 import static com.facebook.presto.operator.scalar.RegexpFunctions.regexpLike;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import static org.openjdk.jmh.annotations.Mode.AverageTime;
 import static org.openjdk.jmh.annotations.Scope.Thread;
 
 @Fork(1)
 @Warmup(iterations = 10)
 @Measurement(iterations = 10)
 {
     @Benchmark
     public boolean benchmarkLike(DotStarAroundData data)
     {
         return regexpLike(data.getSource(), data.getPattern());
     }
 
     @State()
     public static class DotStarAroundData
     {
         @Param({ ".*x.*"".*(x|y).*""longdotstar""phone""literal" })
         private String patternString;
 
         @Param({ "1024""32768" })
         private int sourceLength;
 
         private Regex pattern;
         private Slice source;
 
         @Setup
         public void setup()
         {
             SliceOutput sliceOutput = new DynamicSliceOutput();
             switch () {
                 case ".*x.*":
                      = RegexpFunctions.castToRegexp(Slices.utf8Slice(".*x.*"));
                     IntStream.generate(() -> 97).limit().forEach(sliceOutput::appendByte);
                     break;
                 case ".*(x|y).*":
                      = RegexpFunctions.castToRegexp(Slices.utf8Slice(".*(x|y).*"));
                     IntStream.generate(() -> 97).limit().forEach(sliceOutput::appendByte);
                     break;
                 case "longdotstar":
                      = RegexpFunctions.castToRegexp(Slices.utf8Slice(".*coolfunctionname.*"));
                     ThreadLocalRandom.current().ints(97, 123).limit().forEach(sliceOutput::appendByte);
                     break;
                 case "phone":
                      = RegexpFunctions.castToRegexp(Slices.utf8Slice("\\d{3}/\\d{3}/\\d{4}"));
                     // 47: '/', 48-57: '0'-'9'
                     ThreadLocalRandom.current().ints(47, 58).limit().forEach(sliceOutput::appendByte);
                     break;
                 case "literal":
                      = RegexpFunctions.castToRegexp(Slices.utf8Slice("literal"));
                     // 97-122: 'a'-'z'
                     ThreadLocalRandom.current().ints(97, 123).limit().forEach(sliceOutput::appendByte);
                     break;
             }
              = sliceOutput.slice();
            checkState(.length() == "source.length=%s, sourceLength=%s".length(), );
        }
        public Slice getSource()
        {
            return ;
        }
        public Regex getPattern()
        {
            return ;
        }
    }
    public static void main(String[] args)
            throws RunnerException
    {
        Options options = new OptionsBuilder()
                .verbosity(.)
                .include(".*" + RegexpFunctionsBenchmark.class.getSimpleName() + ".*")
                .build();
        new Runner(options).run();
    }
New to GrepCode? Check out our FAQ X