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 com.google.caliper.Runner; 20import com.google.caliper.SimpleBenchmark; 21 22public class StringIsEmptyBenchmark extends SimpleBenchmark { 23 public void timeIsEmpty_NonEmpty(int reps) { 24 boolean result = true; 25 for (int i = 0; i < reps; ++i) { 26 result &= !("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".isEmpty()); 27 } 28 if (!result) throw new RuntimeException(); 29 } 30 31 public void timeIsEmpty_Empty(int reps) { 32 boolean result = true; 33 for (int i = 0; i < reps; ++i) { 34 result &= ("".isEmpty()); 35 } 36 if (!result) throw new RuntimeException(); 37 } 38 39 public void timeLengthEqualsZero(int reps) { 40 boolean result = true; 41 for (int i = 0; i < reps; ++i) { 42 result &= !("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".length() == 0); 43 } 44 if (!result) throw new RuntimeException(); 45 } 46 47 public void timeEqualsEmpty(int reps) { 48 boolean result = true; 49 for (int i = 0; i < reps; ++i) { 50 result &= !"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".equals(""); 51 } 52 if (!result) throw new RuntimeException(); 53 } 54} 55