• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package benchmarks.regression;
18 
19 import com.google.caliper.Runner;
20 import com.google.caliper.SimpleBenchmark;
21 
22 public class StringIsEmptyBenchmark extends SimpleBenchmark {
timeIsEmpty_NonEmpty(int reps)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 
timeIsEmpty_Empty(int reps)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 
timeLengthEqualsZero(int reps)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 
timeEqualsEmpty(int reps)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