Page 1 of 1

is @ on function damn slow?

Posted: Tue Apr 18, 2006 7:06 am
by jmut
Hi,
I was told that @ operator slows down function call like 400%.
Is this any true?

Posted: Tue Apr 18, 2006 7:24 am
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

Posted: Tue Apr 18, 2006 7:36 am
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 @.

Posted: Tue Apr 18, 2006 7:42 am
by malcolmboston
probably because you are surpressing a potential error therefore carrying on processing code whereas without surpressing the error it would automatically quit?

Posted: Tue Apr 18, 2006 7:43 am
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

Posted: Tue Apr 18, 2006 7:46 am
by Oren
When you use '@' no errors will be reported regardless to your error reporting level.

Posted: Tue Apr 18, 2006 7:49 am
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 @

Posted: Tue Apr 18, 2006 8:05 am
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

Posted: Tue Apr 18, 2006 8:55 am
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.

Posted: Tue Apr 18, 2006 11:41 am
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