lib/performance_analysis: keep the sum execution time
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 20 Jul 2015 04:17:57 +0000 (00:17 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 20 Jul 2015 19:37:47 +0000 (15:37 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/performance_analysis.nit

index 93d525d..1ca255b 100644 (file)
@@ -81,6 +81,9 @@ class PerfEntry
        # Number of registered events
        var count = 0
 
+       # Total execution time of this event
+       var sum = 0.0
+
        # Register a new event execution time with a `Timespec`
        fun add(lapse: Timespec) do add_float lapse.to_f
 
@@ -90,9 +93,10 @@ class PerfEntry
                if time.to_f < min.to_f or count == 0 then min = time
                if time.to_f > max.to_f then max = time
 
-               avg = (avg * count.to_f + time) / (count+1).to_f
+               sum += time
                count += 1
+               avg = sum / count.to_f
        end
 
-       redef fun to_s do return "min {min}, max {max}, avg {avg}, count {count}"
+       redef fun to_s do return "min {min}, max {max}, avg {avg}, sum {sum}, count {count}"
 end