-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-performance.php
More file actions
59 lines (40 loc) · 1.38 KB
/
test-performance.php
File metadata and controls
59 lines (40 loc) · 1.38 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
<?php
function getCpuElapsedTime()
{
if (function_exists("getrusage")) {
$data = getrusage();
$userTime = $data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000;
$systemTime = $data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000;
$totalTime = $userTime + $systemTime;
return $totalTime;
}
return 0;
}
$startCpu = getCpuElapsedTime();
$startTime = microtime(1);
$startMem = memory_get_usage();
#####################################################
$iterations = 1000;
for ($_i = 0; $_i < $iterations; $_i++) {
// iterations: 1000, time: 0.273 sec, memory diff: 22.94 kB, cpu: 0.151 sec
file_get_contents('http://localhost');
// iterations: 1000, time: 0.298 sec, memory diff: 19.06 kB, cpu: 0.166 sec
// $curl = curl_init('http://localhost');
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($curl, CURLOPT_TIMEOUT, 1);
// curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
// curl_exec($curl);
// curl_close($curl);
}
#####################################################
$endTime = microtime(1);
$endMem = memory_get_peak_usage();
if (PHP_SAPI != 'cli')
echo '<pre>';
printf("iterations: %d, time: %.3f sec, memory diff: %.2f kB, cpu: %.3f sec\n",
$iterations,
$endTime - $startTime,
($endMem - $startMem) / 1000,
getCpuElapsedTime() - $startCpu
);
?>