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