2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.search;
20
import org.apache.solr.search.BitDocSet;
21
import org.apache.solr.search.HashDocSet;
22
import org.apache.solr.search.DocSet;
23
import org.apache.lucene.util.OpenBitSet;
25
import java.util.Random;
26
import java.util.BitSet;
30
public class DocSetPerf {
32
// use test instead of assert since asserts may be turned off
33
public static void test(boolean condition) {
35
throw new RuntimeException("test requestHandler: assertion failed!");
39
static Random rand = new Random();
44
static HashDocSet hds;
45
static int[] ids; // not unique
47
static void generate(int maxSize, int bitsToSet) {
48
bs = new OpenBitSet(maxSize);
49
ids = new int[bitsToSet];
52
for (int i=0; i<bitsToSet; i++) {
53
int id=rand.nextInt(maxSize);
60
bds = new BitDocSet(bs,bitsToSet);
61
hds = new HashDocSet(ids,0,count);
66
public static void main(String[] args) {
67
String bsSize=args[0];
68
boolean randSize=false;
70
if (bsSize.endsWith("-")) {
71
bsSize=bsSize.substring(0,bsSize.length()-1);
75
int bitSetSize = Integer.parseInt(bsSize);
76
int numSets = Integer.parseInt(args[1]);
77
int numBitsSet = Integer.parseInt(args[2]);
78
String test = args[3].intern();
79
int iter = Integer.parseInt(args[4]);
83
OpenBitSet[] sets = new OpenBitSet[numSets];
84
DocSet[] bset = new DocSet[numSets];
85
DocSet[] hset = new DocSet[numSets];
86
BitSet scratch=new BitSet();
88
for (int i=0; i<numSets; i++) {
89
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
95
long start = System.currentTimeMillis();
97
if ("test".equals(test)) {
98
for (int it=0; it<iter; it++) {
99
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
103
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
105
OpenBitSet res = ((OpenBitSet)bs1.clone());
107
int icount = (int)res.cardinality();
109
test(bds1.intersection(bds).size() == icount);
110
test(bds1.intersectionSize(bds) == icount);
111
if (bds1.intersection(hds).size() != icount) {
112
DocSet ds = bds1.intersection(hds);
113
System.out.println("STOP");
116
test(bds1.intersection(hds).size() == icount);
117
test(bds1.intersectionSize(hds) == icount);
118
test(hds1.intersection(bds).size() == icount);
119
test(hds1.intersectionSize(bds) == icount);
120
test(hds1.intersection(hds).size() == icount);
121
test(hds1.intersectionSize(hds) == icount);
130
if (test.endsWith("B")) { type="B"; }
131
if (test.endsWith("H")) { type="H"; }
132
if (test.endsWith("M")) { type="M"; }
133
if (test.startsWith("intersect")) oper="intersect";
134
if (test.startsWith("intersectSize")) oper="intersectSize";
135
if (test.startsWith("intersectAndSize")) oper="intersectSize";
139
for (int it=0; it<iter; it++) {
140
int idx1 = rand.nextInt(numSets);
141
int idx2 = rand.nextInt(numSets);
142
DocSet a=null,b=null;
145
a=bset[idx1]; b=bset[idx2];
146
} else if (type=="H") {
147
a=hset[idx1]; b=bset[idx2];
148
} else if (type=="M") {
158
if (oper=="intersect") {
159
DocSet res = a.intersection(b);
160
ret += res.memSize();
161
} else if (oper=="intersectSize") {
162
ret += a.intersectionSize(b);
163
} else if (oper=="intersectAndSize") {
164
DocSet res = a.intersection(b);
172
long end = System.currentTimeMillis();
173
System.out.println("TIME="+(end-start));
175
// System.out.println("ret="+ret + " scratchsize="+scratch.size());
176
System.out.println("ret="+ret);