Hello, please sign in or register
You are here: Home

PHP Optimisation Pass-By-Reference Vs Pass-Value

I was wondering if passing-by-reference was quicker, because memory was not being duplicated.

Answer: No, its not for this little test. Passby-reference took 5.5 seconds, compared to 4.1 seconds without.

<?php
/**
 * Benchmark pass-by-reference vs pass-by-value
 */
$a=$_SERVER;

function a(&$a){$a=array_filter($a);}
function b($a){$a=array_filter($a);}

$t = microtime(true);

for( $i=0; $i < 100000; $i++)
	a($a);
	
print microtime(true) - $t;
print "\n";

$t = microtime(true);

for( $i=0; $i < 100000; $i++)
	b($a);

print microtime(true) - $t;
print "\n";
	
?>

 

Comments

hfBTSbvzZt
I am totally wowed and prpeaerd to take the next step now.
Created 08/08/11
CYnPbIdaOO
NxL2O3 amupodsgeufl
Created 09/08/11
YJQiUOwUnNwkWeie
W3foS7 , [url=http://yxiksvhpdtww.com/]yxiksvhpdtww[/url], [link=http://wpwzjifxqmtr.com/]wpwzjifxqmtr[/link], http://tztlmvbifdci.com/
Created 09/08/11
DphLQZhJbt
U7khVT ymvywgrmjsgw
Created 11/08/11
WpjKpPpRojMcqJ
XzDI6Z , [url=http://xugbpbfxyuld.com/]xugbpbfxyuld[/url], [link=http://bxsxyiwtgbar.com/]bxsxyiwtgbar[/link], http://upwestuilehw.com/
Created 16/08/11
0921maoqiuyun
cheap nba jerseys, http://www.nbajerseys.net/ jordan shoes, http:/...
Created 21/09/15
guoyanying
But the replica watches sentry reebok shoes knew abercrombie and fitch uk his
Created 07/10/15
1015maoqiuyun
coach outlet online, http://www.coachoutletonline-store.us.com/
Created 15/10/15
oakleysunglasses
“I canada goose outlet think it doesn’t swarovski jewelry bode very
Created 21/01/16
linpingping
The michael--kors.org.uk next ralph lauren outlet day patriots jersey Mrs
Created 01/03/16
mmdr
yeezy boost 350 yeezy boost 350 yeezy boost 350
Created 25/03/16
clibin
Tyrion 5c cases watched her ray ban sunglasses read. His timber...
Created 18/04/16
chenyan
Bond grinned. pandora-bracciali.it "We bcbgmax.in.net only chaussure...
Created 15/06/16
chenyan
Bond grinned. pandora-bracciali.it "We bcbgmax.in.net only chaussure...
Created 15/06/16
ninestab123
ninest123 One canada goose pas cher gucci outlet thing
Created 21/07/16
ZZZZ
michael kors handbags nike trainers
Created 05/10/16
cc
discount oakley sunglasses retro jordans
Created 26/10/16
michael kors factory outlet
adidas nmd pandora bracelet
Created 16/05/17
Title*
Comment

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Contact
Name*
Email never shown*
Home Page

Author

Andrew Dodson
Since:Feb 2007

Comment | flag

Categories

Bookmark and Share