-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbenchmark_eval.php
More file actions
54 lines (44 loc) · 1.33 KB
/
benchmark_eval.php
File metadata and controls
54 lines (44 loc) · 1.33 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
<?php
declare(strict_types=1);
/** @noinspection AutoloadingIssuesInspection */
$numbers = range(0, 1000);
include "Collection.php";
$instances=100000;
$exist=true;
function ping($pong) {
return $pong;
}
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
$r=ping("pong");
}
$t2=microtime(true);
$table['no_eval']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
eval('$r=ping("pong");');
}
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['eval']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
$r=eval('return ping("pong");');
}
// note: $r=eval('ping("pong");'); return null
// note: $r=eval('return ping("pong");'); return 'pong'
$t2=microtime(true);
$table['eval2']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
$fnname='ping';
for($i=0;$i<$instances;$i++) {
$r=$fnname("pong");
}
$t2=microtime(true);
$table['dynamic_function']=$t2-$t1;
echo \mapache_commons\Collection::generateTable($table);