how to display php search engine execution time and number of results before the results
ok so i built a php search engine and it was working beautifully, but some people said to me that it was slow.
maybe it may appear slow on their machines when the thing outputs the results table on html but i know it's running ludicrously fast.
so i decided to make a fancy feature like the one many search engines like google have saying that ''your search returned X results in Y time'' as a way of telling people that probably isn't my search engine fault that they're taking a long time to see the results for their query.
i've made the feature that pretty much confirms what i already know, that is that the search engine is fast.
the problem is the results are echoed before the ti开发者_JAVA技巧mer/resultcounter thing is, because for it to count the results it already has to have the results and for it to display the time it took to find them obviously the search engine had to finish running.
i'm using html+css+php for this project and i don't want to have to use javascript, how should i display the timer / results counter before the actual results?
You can run the search
queries with the time
code, then echo them after the search has finished with the time
code coming first.
$start = microtime(true);
$searchdata = //Search Functions
$end = microtime(true);
$time = ($end - $start);
echo $time."".$searchdata
<?PHP
$print=null;
$start=microtime();
echo 'etc etc you just found the results<br><br>';
$print= '<br><br>It took '. number_format(microtime()-$start,12).' seconds to find the results.<br><br>';
echo 'etc etc do what else is to be done, end of script<br>';
echo '__________________________________________________________<br><br>';
echo $print,'It took ', number_format(microtime()-$start,12),' seconds in total.';
?>
$start_time = microtime(true);
.
.
//Search Logic
.
.
$end_time = microtime(true);
$time = ($end_time - $start_time);
echo "Search Time : ".$time." sec\t";
精彩评论