-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
92 lines (65 loc) · 1.84 KB
/
example.php
File metadata and controls
92 lines (65 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
error_reporting(E_ALL);
include "src/Extras.php";
include "src/Interval.php";
include "src/Report.php";
include "src/Timer.php";
include "src/Exceptions/ReportException.php";
/**
* @param int $iterations
* @return array
*/
$func_cycle_1 = function (int $iterations) {
$values = [];
for ($i = 0; $i < $iterations; $i++) {
$values[] = md5(rand(0, 1000000));
}
return $values;
};
/**
* @param int $iterations
* @return array
*/
$func_cycle_2 = function (int $iterations) {
$values = [];
for ($i = 0; $i < $iterations; $i++) {
$values[] = md5(rand(0, 1000000));
}
return $values;
};
// Create new timer
$timer = new Nullform\AppTimer\Timer("New timer", ['Foo' => "Bar"]);
// Report file options
// $timer->report_filename = "AppTimerReport.log";
// $timer->report_dir = dirname(__FILE__);
// $timer->report_file_append = true;
// Parent interval for cycles
$cycles_interval = $timer->start("Cycles");
// Interval for $func_cycle_1()
$timer->start("Cycle 1", ['Iterations' => "1000"]);
$func_cycle_1(1000);
$timer->stop();
// Interval for $func_cycle_2()
$cycle_2_interval = $timer->start("Cycle 2");
// Alternative way to add additional information
$cycle_2_interval->extras()->add("Iterations", "10000");
$func_cycle_2(10000);
$stopped_interval = $timer->stop(['Iterations complete' => 10000]);
$stopped_interval->extras()->remove("Iterations");
$timer->stop();
$timer->start("Going to sleep");
sleep(1);
$timer->stop(['Seconds' => 1]);
// Get parent interval duration
$cycles_interval_duration = $cycles_interval->duration;
// Create report
$report = $timer->report();
// Report as JSON-string
$report_json = $report->toJSON();
// Report as string
$report_string = $report->toString();
if ($report->sapi != "cli") {
echo "<pre>" . $report_string . "</pre>";
} else {
echo $report_string;
}