Beispiel #1
0
 private Comparator<PolicyStats> makeComparator() {
   switch (settings.report().sortBy().toLowerCase()) {
     case "policy":
       return Comparator.comparing(PolicyStats::name);
     case "hit rate":
       return Comparator.comparingDouble(PolicyStats::hitRate);
     case "hits":
       return Comparator.comparingLong(PolicyStats::hitCount);
     case "misses":
       return Comparator.comparingLong(PolicyStats::missCount);
     case "evictions":
       return Comparator.comparingLong(PolicyStats::evictionCount);
     case "steps":
       return Comparator.comparingLong(PolicyStats::operationCount);
     case "time":
       return Comparator.comparingLong(stats -> stats.stopwatch().elapsed(TimeUnit.NANOSECONDS));
     default:
       throw new IllegalArgumentException("Unknown sort order: " + settings.report().sortBy());
   }
 }
Beispiel #2
0
 /** Writes the report to the output destination. */
 @Override
 public void print() throws IOException {
   results.sort(comparator());
   String report = assemble(results);
   String output = settings.report().output();
   if (output.equalsIgnoreCase("console")) {
     System.out.println(report);
   } else {
     File file = Paths.get(output).toFile();
     Files.write(report, file, Charsets.UTF_8);
   }
 }
Beispiel #3
0
  public CountMin64TinyLfu(Config config) {
    BasicSettings settings = new BasicSettings(config);
    sampleSize = 10 * settings.maximumSize();

    if (settings.tinyLfu().conservative()) {
      sketch =
          new ConservativeAddSketch(
              settings.tinyLfu().countMin64().eps(),
              settings.tinyLfu().countMin64().confidence(),
              settings.randomSeed());
    } else {
      sketch =
          new CountMinSketch(
              settings.tinyLfu().countMin64().eps(),
              settings.tinyLfu().countMin64().confidence(),
              settings.randomSeed());
    }
  }
Beispiel #4
0
 /** Returns a comparator that sorts by the specified column. */
 private Comparator<PolicyStats> comparator() {
   Comparator<PolicyStats> comparator = makeComparator();
   return settings.report().ascending() ? comparator : comparator.reversed();
 }