• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.BeforeExperiment;
20 import com.google.caliper.Param;
21 import java.util.BitSet;
22 
23 public class BitSetBenchmark {
24     @Param({ "1000", "10000" })
25     private int size;
26 
27     private BitSet bs;
28 
29     @BeforeExperiment
setUp()30     protected void setUp() throws Exception {
31         bs = new BitSet(size);
32     }
33 
timeIsEmptyTrue(int reps)34     public void timeIsEmptyTrue(int reps) {
35         for (int i = 0; i < reps; ++i) {
36             if (!bs.isEmpty()) throw new RuntimeException();
37         }
38     }
39 
timeIsEmptyFalse(int reps)40     public void timeIsEmptyFalse(int reps) {
41         bs.set(bs.size() - 1);
42         for (int i = 0; i < reps; ++i) {
43             if (bs.isEmpty()) throw new RuntimeException();
44         }
45     }
46 
timeGet(int reps)47     public void timeGet(int reps) {
48         for (int i = 0; i < reps; ++i) {
49             bs.get(i % size);
50         }
51     }
52 
timeClear(int reps)53     public void timeClear(int reps) {
54         for (int i = 0; i < reps; ++i) {
55             bs.clear(i % size);
56         }
57     }
58 
timeSet(int reps)59     public void timeSet(int reps) {
60         for (int i = 0; i < reps; ++i) {
61             bs.set(i % size);
62         }
63     }
64 
timeSetOn(int reps)65     public void timeSetOn(int reps) {
66         for (int i = 0; i < reps; ++i) {
67             bs.set(i % size, true);
68         }
69     }
70 
timeSetOff(int reps)71     public void timeSetOff(int reps) {
72         for (int i = 0; i < reps; ++i) {
73             bs.set(i % size, false);
74         }
75     }
76 }
77