Don't run this benchmark with a query that doesn't use {@link Granularities#ALL},
this pagination function probably doesn't work correctly in that case.
767506
private SelectQuery incrementQueryPagination(SelectQuery query, SelectResultValue prevResult)
  {
    Map<String, Integer> pagingIdentifiers = prevResult.getPagingIdentifiers();
    Map<String, Integer> newPagingIdentifers = new HashMap<>();

    for (String segmentId : pagingIdentifiers.keySet()) {
      int newOffset = pagingIdentifiers.get(segmentId) + 1;
      newPagingIdentifers.put(segmentId, newOffset);
    }

    return query.withPagingSpec(new PagingSpec(newPagingIdentifers, pagingThreshold));
  }
475881
private void computeDistances(ModifiableDoubleDBIDList nlist, DBIDIter query, final DistanceQuery<O> distQuery, Relation<O> relation) {
    nlist.clear();
    O qo = relation.get(query);
    for(DBIDIter ri = relation.iterDBIDs(); ri.valid(); ri.advance()) {
      if(!includeSelf && DBIDUtil.equal(ri, query)) {
        continue;
      }
      double dist = distQuery.distance(qo, ri);
      if(dist != dist) { /* NaN */
        dist = Double.POSITIVE_INFINITY;
      }
      nlist.add(dist, ri);
    }
    nlist.sort();
  }
142806
private OJBIterator getReportQueryIteratorFromQuery(Query query, ClassDescriptor cld) throws PersistenceBrokerException
    {
        RsIteratorFactory factory = ReportRsIteratorFactoryImpl.getInstance();
        OJBIterator result = getRsIteratorFromQuery(query, cld, factory);

        if (query.usePaging())
        {
            result = new PagingIterator(result, query.getStartAtIndex(), query.getEndAtIndex());
        }

        return result;
    }
239034
def paginate_query(self, query):
        

        if self.paginator is None:
            return None

        return self.paginator.paginate_query(query, self.request)
1169143
private void runMultigetSliceQuery(final List<K> param) {
		MultigetSliceQuery<K, N, V> multigetSliceQuery = HFactory
				.createMultigetSliceQuery(keyspace, keySerializer,
						nameSerializer, valueSerializer);

		multigetSliceQuery.setColumnFamily(columnFamily);

		multigetSliceQuery.setKeys(param);

		multigetSliceQuery.setRange(start, finish, reversed, maxColumnCount);

		QueryResult<Rows<K, N, V>> result = multigetSliceQuery.execute();

		queryResult.add(result.get());

		// Add current query execution time to internal variable
		// totalExecutionTimeMicro. When parallelism is enabled, this value might not be correct 
		// always due to available system resources and thread implementation
		totalExecutionTimeMicro.addAndGet(result.getExecutionTimeMicro());
		// Add current query execution time to internal variable
		// totalExecutionTimeNano. When parallelism is enabled, this value might not be correct 
		// always due to available system resources and thread implementation
		totalExecutionTimeNano.addAndGet(result.getExecutionTimeNano());
		
		//Add host used to the list
		m_hostsUsed.put(result.getHostUsed().getIp(), result.getHostUsed());

	}
1002789
function queryFunction(query) {
    var term = query.term;
    var offset = query.offset || 0;
    var results = cities.filter(function(city) {
        return transformText(city).indexOf(transformText(term)) > -1;
    });
    results.sort(function(a, b) {
        a = transformText(a);
        b = transformText(b);
        var startA = (a.slice(0, term.length) === term),
            startB = (b.slice(0, term.length) === term);
        if (startA) {
            return (startB ? (a > b ? 1 : -1) : -1);
        } else {
            return (startB ? 1 : (a > b ? 1 : -1));
        }
    });
    setTimeout(query.callback({
        more: results.length > offset + 10,
        results: results.slice(offset, offset + 10)
    }), 500);
}
581757
public void output(final Map<String, Map<String, List<BigDecimal>>> benchmarks) {
		for (Entry<String, Map<String, List<BigDecimal>>> benchmark : benchmarks.entrySet()) {
			BigDecimal max = benchmark.getValue().values().stream()
				.flatMap(list -> list.stream())
				.max(Comparator.naturalOrder())
				.orElse(BigDecimal.ONE);

			System.out.println(benchmark.getKey().toUpperCase(Locale.ENGLISH));
			System.out.println();

			System.out.println("<div class=\"table-responsive\"><table class=\"table benchmark\">");

			System.out.println("\t<thead>");
			System.out.println("\t\t<tr>");
			System.out.println("\t\t\t<th>Framework</th>");
			System.out.println("\t\t\t<th>Processed Log Entries per Second</th>");
			System.out.println("\t\t</tr>");
			System.out.println("\t</thead>");

			System.out.println("\t<tbody>");

			for (Entry<String, Framework> framework : frameworks.entrySet()) {
				List<BigDecimal> scores = benchmark.getValue().get(framework.getKey());

				for (int i = 0; i < scores.size(); ++i) {
					BigDecimal total = scores.get(i).setScale(0, RoundingMode.HALF_UP);
					BigDecimal percentage = scores.get(i).multiply(PERCENTAGE).divide(max, DECIMAL_PLACES, RoundingMode.HALF_UP);

					String label = i == 0 ? framework.getValue().getName() : framework.getValue().getAsync();

					System.out.println("\t\t" + (i == 0 ? "<tr>" : "<tr class=\"advanced\">"));
					System.out.println("\t\t\t<td>" + label + "</td>");
					System.out.println("\t\t\t<td>");
					System.out.println("\t\t\t\t<div class=\"bar\" style=\"width: " + percentage + "%\">&nbsp;</div>");
					System.out.println("\t\t\t\t<div class=\"total\">" + NUMBER_FORMAT.format(total) + "</div></td>");
					System.out.println("\t\t\t</td>");
					System.out.println("\t\t</tr>");
				}
			}

			System.out.println("\t</tbody>");

			System.out.println("</table></div>");
			System.out.println();
		}
	}
1111984
private static Druids.ScanQueryBuilder basicA(final BenchmarkSchemaInfo basicSchema)
  {
    final QuerySegmentSpec intervalSpec =
        new MultipleIntervalSegmentSpec(Collections.singletonList(basicSchema.getDataInterval()));

    return Druids.newScanQueryBuilder()
                 .dataSource("blah")
                 .intervals(intervalSpec)
                 .order(ordering);
  }
819787
@Override
    public List<DistinctQueryResult> divide() {
        return Lists.newArrayList(Iterators.transform(getResultData(), new Function<QueryRow, DistinctQueryResult>() {
    
            @Override
            public DistinctQueryResult apply(final QueryRow input) {
                Set<QueryRow> resultData = new LinkedHashSet<>();
                resultData.add(input);
                return new AggregationDistinctQueryResult(getColumnLabelAndIndexMap(), resultData.iterator(), metaData);
            }
        }));
    }
1249958
@Override
  public final Long evalLongResult(
    final String pQuery, final String pColumnName) throws Exception {
    Long result = null;
    IRecordSet<RS> recordSet = null;
    try {
      recordSet = retrieveRecords(pQuery);
      if (recordSet.moveToFirst()) {
        result = recordSet.getLong(pColumnName);
      }
    } finally {
      if (recordSet != null) {
        recordSet.close();
      }
    }
    return result;
  }
49473
CloseableIterator<T> seperateIteratorThrow(int flags) throws SQLException {
		// check state to make sure we have a DAO in case we have a deserialized collection
		if (dao == null) {
			throw new IllegalStateException(
					"Internal DAO object is null.  Maybe the collection was deserialized or otherwise constructed wrongly.  "
							+ "Use dao.assignEmptyForeignCollection(...) or dao.getEmptyForeignCollection(...) instead");
		} else {
			return dao.iterator(getPreparedQuery(), flags);
		}
	}
688730
public Result run(Database database, Relation<O> relation, Relation<NumberVector> radrel) {
    if(queries != null) {
      throw new AbortException("This 'run' method will not use the given query set!");
    }
    // Get a distance and kNN query instance.
    DistanceQuery<O> distQuery = database.getDistanceQuery(relation, getDistanceFunction());
    RangeQuery<O> rangeQuery = database.getRangeQuery(distQuery);

    final DBIDs sample = DBIDUtil.randomSample(relation.getDBIDs(), sampling, random);
    FiniteProgress prog = LOG.isVeryVerbose() ? new FiniteProgress("kNN queries", sample.size(), LOG) : null;
    int hash = 0;
    MeanVariance mv = new MeanVariance();
    for(DBIDIter iditer = sample.iter(); iditer.valid(); iditer.advance()) {
      double r = radrel.get(iditer).doubleValue(0);
      DoubleDBIDList rres = rangeQuery.getRangeForDBID(iditer, r);
      int ichecksum = 0;
      for(DBIDIter it = rres.iter(); it.valid(); it.advance()) {
        ichecksum += DBIDUtil.asInteger(it);
      }
      hash = Util.mixHashCodes(hash, ichecksum);
      mv.put(rres.size());
      LOG.incrementProcessed(prog);
    }
    LOG.ensureCompleted(prog);
    if(LOG.isStatistics()) {
      LOG.statistics("Result hashcode: " + hash);
      LOG.statistics("Mean number of results: " + mv.getMean() + " +- " + mv.getNaiveStddev());
    }
    return null;
  }
1027685
def _pagination(self):
        

        oldest = self.oldest
        newest = self.newest

        base = {key: val for key, val in self.spec.items()
                if key not in OFFSET_PRIORITY}

        oldest_neighbor = View({
            **base,
            'before': oldest,
            'order': 'newest'
        }).first if oldest else None

        newest_neighbor = View({
            **base,
            'after': newest,
            'order': 'oldest'
        }).first if newest else None

        if 'date' in self.spec:
            return self._get_date_pagination(base, oldest_neighbor, newest_neighbor)

        if 'count' in self.spec:
            return self._get_count_pagination(base, oldest_neighbor, newest_neighbor)

        # we're not paginating
        return None, None
679328
function (params, q) {
            q = q || new Query();

            if (params.sort) {
                this._parseSort(params.sort, q);
            }

            if (params.where) {
                this._parseCondition(params.where, q);
            }

            var undefined;
            if (params.limit !== undefined) {
                var limit = parseInt(params.limit, 10);
                if (!isNaN(limit)) {
                    q.limit(limit);
                }

            }

            if (params.offset !== undefined) {
                var offset = parseInt(params.offset, 10);
                if (!isNaN(offset)) {
                    q.offset(offset);
                }
            }

            return q;
        }
1090574
public Result runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(Query query, int partitionId) {
        MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
        PartitionIdSet partitions = singletonPartitionIdSet(partitionCount, partitionId);

        // first we optimize the query
        Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes(partitionId));

        Collection<QueryableEntry> entries = null;
        Indexes indexes = mapContainer.getIndexes(partitionId);
        if (indexes != null && !indexes.isGlobal()) {
            entries = indexes.query(predicate);
        }

        Result result;
        if (entries == null) {
            result = createResult(query, partitions);
            partitionScanExecutor.execute(query.getMapName(), predicate, partitions, result);
            result.completeConstruction(partitions);
        } else {
            result = populateNonEmptyResult(query, entries, partitions);
        }

        return result;
    }
637715
double run_benchmark() {
    // use the lesser of 40MB or 10% of Heap
    final long M = Math.min(10000000l, Runtime.getRuntime().maxMemory()/40);
    int[] vals = MemoryManager.malloc4((int)M);
    double total;
    int repeats = 20;
    Timer timer = new Timer(); //ms
    long sum = 0;
    // write repeats * M ints
    // read  repeats * M ints
    for (int l=repeats-1; l>=0; --l) {
      for (int i=0; i<M; ++i) {
        vals[i] = i + l;
      }
      sum = 0;
      for (int i=0; i<M; ++i) {
        sum += vals[i];
      }
    }
    total = (double)timer.time()/1000./repeats;
    //use the sum in a way that doesn't affect the result (don't want the compiler to optimize it away)
    double time = total + ((M*(M-1)/2) - sum); // == total
    return (double)2*M*4/time; //(read+write) * 4 bytes
  }
1261944
static Iterator<Page> lazySearch(final Wikipedia wikipedia, final String query) {
    final Response<Page> first = wikipedia.search(query);
    if (first.nextOffset == null) {
      return first.iterator();
    }
    return new Iterator<Page>() {
      Iterator<Page> current = first.iterator();
      Long nextOffset = first.nextOffset;

      @Override
      public boolean hasNext() {
        while (!current.hasNext() && nextOffset != null) {
          System.out.println("Wow.. even more results than " + nextOffset);
          Response<Page> nextPage = wikipedia.resumeSearch(query, nextOffset);
          current = nextPage.iterator();
          nextOffset = nextPage.nextOffset;
        }
        return current.hasNext();
      }

      @Override
      public Page next() {
        return current.next();
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }