Пример #1
0
 private void _benchmark(Lookup lookup, Map<String, Integer> ref, boolean estimate, Bench bench)
     throws Exception {
   long start = System.currentTimeMillis();
   lookup.build(getTFIT());
   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;
   }
 }
Пример #2
0
 private static void runTest(Database db, Bench bench, int size) throws Exception {
   bench.init(db, size);
   bench.runTest();
 }