View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.benchmark;
5   
6   
7   class BenchmarkResult implements Comparable<BenchmarkResult> {
8   
9       public final Benchmark type;
10      public final String name;
11      private long time;
12      private long count;
13      
14      public BenchmarkResult(Benchmark type, String name) {
15          this.type = type;
16          this.name = name;
17      }
18      public BenchmarkResult(Benchmark type, long time, long count) {
19          this(type, type.name);
20          this.time = time;
21          this.count = count;
22      }
23  
24      public long getTime() {     return time;   }
25      public long getCount() {    return count;  }
26      
27      public void update(long time, long count) {
28          this.time += time;
29          this.count += count;
30      }
31  
32      public int compareTo(BenchmarkResult benchmarkResult) {
33          int cmp = type.index - benchmarkResult.type.index;
34          if (cmp == 0) {
35              long delta = this.time - benchmarkResult.time;
36              cmp = delta > 0 ? 1 : (delta < 0 ? -1 : 0);
37          }
38          return cmp;
39      }
40  }