1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package benchmarks.regression; 18 19import java.util.regex.Pattern; 20 21public class StringSplitBenchmark { 22 public void timeStringSplitComma(int reps) { 23 for (int i = 0; i < reps; ++i) { 24 "this,is,a,simple,example".split(","); 25 } 26 } 27 28 public void timeStringSplitLiteralDot(int reps) { 29 for (int i = 0; i < reps; ++i) { 30 "this.is.a.simple.example".split("\\."); 31 } 32 } 33 34 public void timeStringSplitNewline(int reps) { 35 for (int i = 0; i < reps; ++i) { 36 "this\nis\na\nsimple\nexample\n".split("\n"); 37 } 38 } 39 40 public void timePatternSplitComma(int reps) { 41 Pattern p = Pattern.compile(","); 42 for (int i = 0; i < reps; ++i) { 43 p.split("this,is,a,simple,example"); 44 } 45 } 46 47 public void timePatternSplitLiteralDot(int reps) { 48 Pattern p = Pattern.compile("\\."); 49 for (int i = 0; i < reps; ++i) { 50 p.split("this.is.a.simple.example"); 51 } 52 } 53 54 public void timeStringSplitHard(int reps) { 55 for (int i = 0; i < reps; ++i) { 56 "this,is,a,harder,example".split("[,]"); 57 } 58 } 59} 60