/** Creates a new instance of PerfQuery */ public PerfQuery() { results = new TFloatArrayList[4]; results[BRUTE_FORCE] = new TFloatArrayList(); results[HAND_CODED] = new TFloatArrayList(); results[INDEXED] = new TFloatArrayList(); results[INDEX_CREATE] = new TFloatArrayList(); }
/** * Adds the values in the array <tt>vals</tt> to the end of the * list, in order. * * @param vals an <code>float[]</code> value */ public void add(float[] vals) { add(vals, 0, vals.length); }
/** * Searches the list for values satisfying <tt>condition</tt> in * the manner of the *nix <tt>grep</tt> utility. * * @param condition a condition to apply to each element in the list * @return a list of values which match the condition. */ public TFloatArrayList grep(TFloatProcedure condition) { TFloatArrayList list = new TFloatArrayList(); for (int i = 0; i < _pos; i++) { if (condition.execute(_data[i])) { list.add(_data[i]); } } return list; }
/** * Inserts <tt>value</tt> into the list at <tt>offset</tt>. All * values including and to the right of <tt>offset</tt> are shifted * to the right. * * @param offset an <code>int</code> value * @param value an <code>float</code> value */ public void insert(int offset, float value) { if (offset == _pos) { add(value); return; } ensureCapacity(_pos + 1); // shift right System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); // insert _data[offset] = value; _pos++; }
private void printSummary() { System.out.println("Query Execution Performance Results Summary"); System.out.println("num iterations = " + NUM_ITERATIONS); System.out.println(); System.out.println("Average query execution time in ms"); System.out.println(); String[] setNames = new String[] {"33% Retrieval", "0% Retrieval"}; for (int setI = 0; setI < setNames.length; setI++) { String setName = setNames[setI]; System.out.println(setName + ":"); System.out.println("dataset size,hand-coded,brute-force,indexed,[index-create-time]"); for (int szi = 0; szi < DATA_SET_SIZES.length; szi++) { System.out.print(DATA_SET_SIZES[szi]); System.out.print(','); for (int ti = HAND_CODED; ti <= INDEX_CREATE; ti++) { // skip over first set of each type, which was warm up int ix = ((setI + 1) * DATA_SET_SIZES.length) + szi; System.out.print(results[ti].get(ix)); if (ti < INDEX_CREATE) { System.out.print(','); } } System.out.println(); } System.out.println(); } }
/** * Adds <tt>val</tt> to the end of the list, growing as needed. * * @param val an <code>float</code> value */ public void add(float val) { ensureCapacity(_pos + 1); _data[_pos++] = val; }
/** * Searches the list back to front for the last index of * <tt>value</tt>. * * @param value an <code>float</code> value * @return the last offset of the value, or -1 if it is not in * the list. * @see #binarySearch(float) for faster searches on sorted lists */ public int lastIndexOf(float value) { return lastIndexOf(_pos, value); }
/** * Searches the list front to back for the index of * <tt>value</tt>. * * @param value an <code>float</code> value * @return the first offset of the value, or -1 if it is not in * the list. * @see #binarySearch(float) for faster searches on sorted lists */ public int indexOf(float value) { return indexOf(0, value); }
/** * Flushes the internal state of the list, resetting the capacity * to the default. */ public void clear() { clear(DEFAULT_CAPACITY); }
/** * Sets the size of the list to 0, but does not change its * capacity. This method can be used as an alternative to the * {@link #clear() clear} method if you want to recyle a list without * allocating new backing arrays. * * @see #clear() */ public void reset() { _pos = 0; fill(0); }
/** * Inserts the array of <tt>values</tt> into the list at * <tt>offset</tt>. All values including and to the right of * <tt>offset</tt> are shifted to the right. * * @param offset an <code>int</code> value * @param values an <code>float[]</code> value */ public void insert(int offset, float[] values) { insert(offset, values, 0, values.length); }
/** * Performs a binary search for <tt>value</tt> in the entire list. * Note that you <b>must</b> @{link #sort sort} the list before * doing a search. * * @param value the value to search for * @return the absolute offset in the list of the value, or its * negative insertion point into the sorted list. */ public int binarySearch(float value) { return binarySearch(value, 0, _pos); }
/** * Searches the list for values which do <b>not</b> satisfy * <tt>condition</tt>. This is akin to *nix <code>grep -v</code>. * * @param condition a condition to apply to each element in the list * @return a list of values which do not match the condition. */ public TFloatArrayList inverseGrep(TFloatProcedure condition) { TFloatArrayList list = new TFloatArrayList(); for (int i = 0; i < _pos; i++) { if (! condition.execute(_data[i])) { list.add(_data[i]); } } return list; }
/** * Inserts a slice of the array of <tt>values</tt> into the list * at <tt>offset</tt>. All values including and to the right of * <tt>offset</tt> are shifted to the right. * * @param offset an <code>int</code> value * @param values an <code>float[]</code> value * @param valOffset the offset in the values array at which to * start copying. * @param len the number of values to copy from the values array */ public void insert(int offset, float[] values, int valOffset, int len) { if (offset == _pos) { add(values, valOffset, len); return; } ensureCapacity(_pos + len); // shift right System.arraycopy(_data, offset, _data, offset + len, _pos - offset); // insert System.arraycopy(values, valOffset, _data, offset, len); _pos += len; }
/** * Adds a subset of the values in the array <tt>vals</tt> to the * end of the list, in order. * * @param vals an <code>float[]</code> value * @param offset the offset at which to start copying * @param length the number of values to copy. */ public void add(float[] vals, int offset, int length) { ensureCapacity(_pos + length); System.arraycopy(vals, offset, _data, _pos, length); _pos += length; }
/** * Searches the list for <tt>value</tt> * * @param value an <code>float</code> value * @return true if value is in the list. */ public boolean contains(float value) { return lastIndexOf(value) >= 0; }
/** * Creates a new <code>TFloatArrayList</code> instance whose * capacity is the greater of the length of <tt>values</tt> and * DEFAULT_CAPACITY and whose initial contents are the specified * values. * * @param values an <code>float[]</code> value */ public TFloatArrayList(float[] values) { this(Math.max(values.length, DEFAULT_CAPACITY)); add(values); }
/** * Fills a range in the list with the specified value. * * @param fromIndex the offset at which to start filling (inclusive) * @param toIndex the offset at which to stop filling (exclusive) * @param val the value to use when filling */ public void fill(int fromIndex, int toIndex, float val) { if (toIndex > _pos) { ensureCapacity(toIndex); _pos = toIndex; } Arrays.fill(_data, fromIndex, toIndex, val); }
private void runQuery(Query query, int execType) throws Exception { System.out.println("Executing Query: " + query.getQueryString()); System.out.println("Num iterations=" + NUM_ITERATIONS); System.out.println(); boolean indexed = execType == INDEXED; for (int i = 0; i < DATA_SET_SIZES.length; i++) { int num = DATA_SET_SIZES[i]; populate(num, indexed); System.out.println("Executing (" + execTypeStrings[execType] + ")..."); long startTime = NanoTimer.getTime(); SelectResults results = null; for (int j = 0; j < NUM_ITERATIONS; j++) { results = (SelectResults)query.execute(); } long totalTime = NanoTimer.getTime() - startTime; System.out.println("results size =" + results.size()); float aveTime = totalTime / NUM_ITERATIONS / 1e6f; System.out.println("ave execution time=" + aveTime + " ms"); this.results[execType].add(aveTime); System.out.println(); } System.out.println("--------------------------------------------"); }