-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmark_echo_vs_strings.php
45 lines (38 loc) · 1.21 KB
/
benchmark_echo_vs_strings.php
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
<?php
declare(strict_types=1);
/** @noinspection AutoloadingIssuesInspection */
include "Collection.php";
$instances=2000;
echo "<br>echo:<hr>";
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
echo 'hello world 123456789012345678901234567890';
}
$t2=microtime(true);
$table['echo']=$t2-$t1;
echo "<br>concat:<hr>";
// **********************************************************************************
$t1=microtime(true);
$str='';
for($i=0;$i<$instances;$i++) {
$str.='hello world 123456789012345678901234567890';
}
echo $str;
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['concat']=$t2-$t1;
echo "<br>implode:<hr>";
// **********************************************************************************
$t1=microtime(true);
$str=[];
for($i=0;$i<$instances;$i++) {
$str[]='hello world 123456789012345678901234567890';
}
echo implode('',$str);
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['implode']=$t2-$t1;
echo \mapache_commons\Collection::generateTable($table);