aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRami Jasim <rami.jasim1@uni-oldenburg.de>2025-01-24 15:41:38 +0100
committerRami Jasim <rami.jasim1@uni-oldenburg.de>2025-01-24 15:41:38 +0100
commitb97cea53321ae4da201adc064a11ec6bc20a036f (patch)
tree9976f922442decade61f07d32f99e9f629062f18 /lib
parent9802aaef60e41c6701dbfd2d7d4e14b23abcb81c (diff)
add more data to the timerstudip_modules_performance_test
Diffstat (limited to 'lib')
-rw-r--r--lib/classes/Timer.php24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/classes/Timer.php b/lib/classes/Timer.php
index 8d5ec95..df5c150 100644
--- a/lib/classes/Timer.php
+++ b/lib/classes/Timer.php
@@ -44,11 +44,33 @@ final class Timer
}
$res = [];
foreach ($deltas as $timer_name => $data) {
- $res[$timer_name] = array_sum($data)/count($data);
+ $res[$timer_name]['avg'] = array_sum($data)/count($data);
+ $res[$timer_name]['std_dev'] = $this->standard_deviation($data);
+ $res[$timer_name]['data'] = $data;
}
return $res;
}
+ //src: https://www.geeksforgeeks.org/php-program-find-standard-deviation-array/
+ private function standard_deviation($array): float
+ {
+ $num_of_elements = count($array);
+
+ $variance = 0.0;
+
+ // calculating mean using array_sum() method
+ $average = array_sum($array)/$num_of_elements;
+
+ foreach($array as $i)
+ {
+ // sum of squares of differences between
+ // all numbers and means.
+ $variance += pow(($i - $average), 2);
+ }
+
+ return (float)sqrt($variance/$num_of_elements);
+ }
+
private function compute_delta($data)
{
if (isset($data['start']) && isset($data['end'])) {