is @ on function damn slow?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

is @ on function damn slow?

Post by jmut »

Hi,
I was told that @ operator slows down function call like 400%.
Is this any true?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

not in my experience, u might wanna try what everyone else seems to be doing at the moment, do some benchmark tests and post the results
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

I did some tests.


fopen() existing file w/wihtout @


itterating 10 000 times.
then itterating 1 000 000.

It is approximately 14-15% slowdown using @.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

probably because you are surpressing a potential error therefore carrying on processing code whereas without surpressing the error it would automatically quit?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

malcolmboston wrote:probably because you are surpressing a potential error therefore carrying on processing code whereas without surpressing the error it would automatically quit?
of course there was no error. I have display errors and E_ALL on reporting
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

When you use '@' no errors will be reported regardless to your error reporting level.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Oren wrote:When you use '@' no errors will be reported regardless to your error reporting level.
guys you are definitely not with me here :)
I run the same code:
first without using @
then with using @

what makes you think that it produce errors when I use @
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

well if thats what your benchmarks say then thats what it does, thinking about it carefully its probably extra code at PHP-level that handles it
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm not sure how it is handled when interpreted but I'm guessing there must be some try/catch type of thing that gets called and thus a small slow down.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Here's a test that I ran. I'm not quite sure how to do formal tests, if there is such a thing, but this surely is indicative of the results.

The Test:

Code: Select all

<?php

//	array for storing times
$data_array = array();
$final_array = array();

//	some data for test functions
$test_array = array('1','2','3','4','5','6','a','b','c','d','e','f');

$j=1;
for($i=0;$i<1000000;$i++){
	
	//	start the timer
	$time_start = microtime(1);
	
	//	a test function
	array_reverse($test_array);
	
	//	stop the timer
	$time_end = microtime(1);
	
	//	calculate total time
	$total_time = $time_end-$time_start;
	
	//	store in an array
	$data_array[] = $total_time;
	
	//	need to clear?
	if($j == 100){
		
		//	loop through array and add totals
		$total = '';
		foreach($data_array AS $data){
			$total += $data;
		}
		
		//	get average
		$avg = $total/count($data_array);
		
		//	store in a larger array
		$final_array[] = $avg;
		
		//	clear
		$data_array = array();
		
		//	reset
		$j = 0;
	}
	$j++;

}

//	get the average total time
$final_total = '';
foreach($final_array AS $fdata){
	$final_total += $fdata;
}

echo $final_total/count($final_array);
?>
The results, with different functions:

Code: Select all

1 million iterations for each function

serialize

- without @
	.000013448463916779

- with @
	.000016017480611801


array_flip

- without @
	.000010388954401016
- with @
	.000013084985971451


array_reverse

- without @
	.0000089243161678314
- with @
	.00001143853521347
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply