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