nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: jwrapper: prevent nitls to parse the generated files
[nit.git]
/
lib
/
performance_analysis.nit
diff --git
a/lib/performance_analysis.nit
b/lib/performance_analysis.nit
index
93d525d
..
8403ea7
100644
(file)
--- a/
lib/performance_analysis.nit
+++ b/
lib/performance_analysis.nit
@@
-35,8
+35,8
@@
# end
#
# assert sys.perfs["sleep 1ms"].count == 100
# end
#
# assert sys.perfs["sleep 1ms"].count == 100
-# assert sys.perfs["sleep 1ms"].avg.is_approx(0.001, 0.0001)
-# assert sys.perfs["sleep 5ms"].avg.is_approx(0.005, 0.0005)
+# assert sys.perfs["sleep 1ms"].avg.is_approx(0.001, 0.001)
+# assert sys.perfs["sleep 5ms"].avg.is_approx(0.005, 0.005)
# ~~~
module performance_analysis
# ~~~
module performance_analysis
@@
-81,6
+81,9
@@
class PerfEntry
# Number of registered events
var count = 0
# 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
# 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
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
count += 1
+ avg = sum / count.to_f
end
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
end