-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreference_vs_no_reference.php
More file actions
53 lines (36 loc) · 1.02 KB
/
reference_vs_no_reference.php
File metadata and controls
53 lines (36 loc) · 1.02 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
<?php
/**
* @copyright Jorge Castro Castillo MIT License https://www.eftec.cl
* @version 1.1
*/
include 'Collection.php';
echo "<h1>Reference vs No Reference</h1>";
echo "<p>It tests the performance between a function that returns a value by reference versus the use of return</p>";
$result=[];
$t1=microtime(true);
$array=['a1'=>1,'a2'=>'aaaa','a3'=>50.56];
for($i=0;$i<1000000;$i++) {
reference($array);
}
$t2=microtime(true);
$result['Reference']=$t2-$t1;
$t1=microtime(true);
$array=['a1'=>1,'a2'=>'aaaa','a3'=>50.56];
for($i=0;$i<1000000;$i++) {
$array=noReference($array);
}
$t2=microtime(true);
$result['No Reference']=$t2-$t1;
$result['Speed of Reference %']= 100-( $result['Reference']*100 / $result['No Reference']);
echo \mapache_commons\Collection::generateTable($result);
function reference(&$array) {
$array['a1']=2;
$array['a2']='bbbb';
$array['a4']=55555;
}
function noReference($array) {
$array['a1']=2;
$array['a2']='bbbb';
$array['a4']=55555;
return $array;
}