Example usage for org.apache.lucene.util RamUsageEstimator RamUsageEstimator

List of usage examples for org.apache.lucene.util RamUsageEstimator RamUsageEstimator

Introduction

In this page you can find the example usage for org.apache.lucene.util RamUsageEstimator RamUsageEstimator.

Prototype

private RamUsageEstimator() 

Source Link

Document

No instantiation.

Usage

From source file:org.apache.solr.spelling.suggest.SuggesterTest.java

License:Apache License

private void _benchmark(Lookup lookup, Map<String, Integer> ref, boolean estimate, Bench bench)
        throws Exception {
    long start = System.currentTimeMillis();
    lookup.build(getTFIT());/*w ww.  j  av a 2  s  .c  om*/
    long buildTime = System.currentTimeMillis() - start;
    TermFreqIterator tfit = getTFIT();
    long elapsed = 0;
    while (tfit.hasNext()) {
        String key = tfit.next();
        // take only the first part of the key
        int len = key.length() > 4 ? key.length() / 3 : 2;
        String prefix = key.substring(0, len);
        start = System.nanoTime();
        List<LookupResult> res = lookup.lookup(prefix, true, 10);
        elapsed += System.nanoTime() - start;
        assertTrue(res.size() > 0);
        for (LookupResult lr : res) {
            assertTrue(lr.key.startsWith(prefix));
        }
        if (ref != null) { // verify the counts
            Integer Cnt = ref.get(key);
            if (Cnt == null) { // first pass
                ref.put(key, res.size());
            } else {
                assertEquals(key + ", prefix: " + prefix, Cnt.intValue(), res.size());
            }
        }
    }
    if (estimate) {
        RamUsageEstimator rue = new RamUsageEstimator();
        long size = rue.estimateRamUsage(lookup);
        System.err.println(lookup.getClass().getSimpleName() + " - size=" + size);
    }
    if (bench != null) {
        bench.buildTime += buildTime;
        bench.lookupTime += elapsed;
    }
}