5/29/2013

performance of array_map vs foreach loop


The following is one example for two ways:


$arrayOfNumbers = array();
for($i=1; $i<= 10000; ++$i) {
    $arrayOfNumbers[] = rand(1, 99999);
}
$maxHeap = new SplMaxHeap ();
#first way
# Avg Time: 0.92856907844543s
array_map(array($maxHeap, 'insert'), $arrayOfNumbers);
#second way
# Avg Time: 1.3148670101166
foreach($arrayOfNumbers as $number) {
    $maxHeap->insert($number);
}



It is due to the difference between Callback functions and normal functions.
In the second one, iteration of array using foreach, each iteration calls "insert" function and wait for the execution (function return control) and proceed to next iteration.
But in the array_map function, "insert" happens as callback function, it calls "insert" and don't wait for the result and call insert with next item in the array. So it is faster.


http://www.myresearch.biz/download/IJITCC2012.pdf

5/20/2013

PHP header Redirect for 301 Redirect permanently vs 302 Redirect Temporarily

1. PHP Redirect Code (permanent redirects)

Code 1. 
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.researchbib.com");
?>

2. it is not same with (temporarily redirects)

Code 2.
<?php
header("Location: http://www.researchbib.com"); 
?>

====
<?php
header("HTTP/1.1 302 Moved Temporarily");
header("Location: http://www.researchbib.com");
?>

Please be careful.

If you set A page with code 1 or code 2, it is different for google index result.

Code 1: Google will index http://www.researchbib.com and url is http://www.researchbib.com, which means google will throw away A url. The google will dispaly www.researchbib.com link when usr search this page.

Code 2: Goodle will inex the contents from http://www.researchbib.com and url is A. The google will dispaly A link when usr search this page.



2014 1st International Conference on Non Conventional Energy