is @ on function damn slow?
Moderator: General Moderators
is @ on function damn slow?
Hi,
I was told that @ operator slows down function call like 400%.
Is this any true?
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
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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:
The results, with different functions:
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);
?>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 @
.00001143853521347Set 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.