summaryrefslogtreecommitdiff
path: root/classes/Benchmark.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
commit7076343338ae3439f3c86f01144818abe8c31978 (patch)
tree794abb1e6b8f821091fd095341885496b6dad51d /classes/Benchmark.php
parent47cbb529f5723b246125ae083a193e11481b89ef (diff)
downloadclassroom-7076343338ae3439f3c86f01144818abe8c31978.tar.gz
classroom-7076343338ae3439f3c86f01144818abe8c31978.tar.bz2
classroom-7076343338ae3439f3c86f01144818abe8c31978.zip
add container helpers; constuct public directory-tree
Diffstat (limited to 'classes/Benchmark.php')
-rw-r--r--classes/Benchmark.php150
1 files changed, 0 insertions, 150 deletions
diff --git a/classes/Benchmark.php b/classes/Benchmark.php
deleted file mode 100644
index a7e93ea..0000000
--- a/classes/Benchmark.php
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-
-// define('BENCHMARKED', true); // then you know if class is active
-
-class Benchmark {
-
- private static $timeSpots = Array();
-
- private static $memoryUse = Array();
-
- private static $enableReport = true;
-
-
- /** add_timespot
- * ---
- * add new timespot
- * @param $key : label of timespot
- */
- public static function add_spot(string $key)
- {
- self::$timeSpots[$key] = microtime(true);
- self::$memoryUse[$key] = round(memory_get_usage()/(1024*1024),2);
- }
-
-
- /** exist
- * checks if a benchmark spot with label $key exists
- */
- public static function exist(string $key) : bool
- {
- return isset(self::$timeSpots[$key]);
- }
-
-
- /** desableReport
- * (Self-explanatory)
- */
- public static function disableReport()
- {
- self::$enableReport = false;
- }
-
-
- /** render_benchmark_report
- * ---
- * renders performance report
- * as html comment at the end of webpage in various modes
- * @param $mode (string)
- * + 'comment' (default): include report as html comment
- * + 'html' : include report as a html div
- * + 'code' : include report as a pre/code block
- */
- public static function render_report(string $mode = 'comment' )
- {
- if (self::$enableReport) {
-
- switch ($mode) {
- case 'html':
- $open = '<p>';
- $close = '</b></p>';
- $divider = ":<b>";
- $prefix = '<div>';
- $suffix = '</div>';
- break;
- case 'code':
- $open = '';
- $close = '';
- $divider = ": ";
- $prefix = '<pre>';
- $suffix = '</pre>';
- break;
- case 'comment':
- default:
- $open = '<!--';
- $close = '-->';
- $divider = ":";
- $prefix = '';
- $suffix = '';
- break;
- }
-
- echo $prefix;
-
- // TIME REPORT
- // ---------------------------------------------------------------------
- echo "\n\n{$open} Timings {$close}";
-
- // valid from php 7.3
- // $start = self::$timeSpots[ array_key_first(self::$timespots) ];
- // $end = self::$timeSpots[ array_key_last(self::$timespots) ];
- $start = self::$timeSpots['start'];
- $end = self::$timeSpots['end'];
- $all_dt = number_format($end - $start , 4)*1000 ." ms";
-
-
-
- // if more than 2 timespots
- // echo dt between each spot
- if (count(self::$timeSpots) > 2) {
-
- // calculate dt between spots
- $time_results = array();
- $prev_key = '';
- $prev_time = 0;
- foreach(self::$timeSpots as $key => $t) {
- if (!$prev_time) {
- $prev_time = $t;
- $prev_key = $key;
- }
- else {
- $dt = number_format($t - $prev_time , 4)*1000 ." ms";
- $time_results[] = array(
- 'part' => "{$prev_key}[..{$key}]", ///$key,
- 'dt' => $dt
- );
- $prev_key = $key; //// "{$prev_key}[..{$key}]";
- $prev_time = $t;
- }
- }
-
- // echo timings
- foreach ($time_results as $key => $val) {
- echo "\n\t{$open} {$val['part']} {$divider} {$val['dt']} {$close}";
- }
- }
-
- // echo total time
- echo "\n\t{$open} total {$divider} {$all_dt} {$close}";
-
-
- // MEMORY REPORT
- // ---------------------------------------------------------------------
- echo "\n\n{$open} Memory Usage {$close}";
-
- if (count(self::$memoryUse) > 2) {
-
- foreach (self::$memoryUse as $key => $val) {
- echo "\n\t{$open} {$key} {$divider} {$val}MB {$close}";
- }
-
- } else {
- echo "\n\t{$open} memory usage {$divider} ". round(memory_get_usage()/(1024*1024),2) ."MB {$close}";
- }
-
- echo $suffix;
-
- }
-
- }
-}