1 package com.imcode.db.benchmark; 2 3 public class Average { 4 private String unit ; 5 private long total ; 6 private int count ; 7 8 public Average(String unit) { 9 this.unit = unit; 10 } 11 12 public void add(long time, int count) { 13 total+= time ; 14 this.count+= count; 15 } 16 17 public float getAverage() { 18 if (count == 0) { 19 return 0 ; 20 } 21 return (float) ( total / (double) count ) ; 22 } 23 24 public int getCount() { 25 return count ; 26 } 27 28 public long getTotal() { 29 return total; 30 } 31 32 public String toString() { 33 return "("+total+"ms/"+count+"="+getAverage()+"ms/"+unit+")" ; 34 } 35 }