Yesideez Posted March 19, 2007 Share Posted March 19, 2007 Now that my script for removing duplicate words from a massive word list has been finished I thought I'd add a routine to count the length of time each page takes to be generated. Here is my script: <?php $time_start=getmicrotime(); function getmicrotime() { list($usec,$sec)=explode(" ",microtime()); return ((float)$usec+(float)$sec); } $opmode="get"; $wordlist=""; $txtwordlist=$_POST['txtwordlist']; if ($_POST['subsend']) { $temp=explode("\n",str_replace(" ","\n",$txtwordlist)); $wordcount=count($temp)+1; $wordList=array_unique($temp); $wordunique=count($wordList)+1; $long=array(); foreach ($wordList as $word) { if (trim(strlen($word))>4) { $long[]=array('len' => strlen(trim($word)),'word' => trim($word)); } } rsort($long); $topten=""; for ($i=0;$i<20;$i++) { $topten.=($i<9 ? '0' : '').($i+1).': '.$long[$i]['word'].' ('.$long[$i]['len'].')<br />'; } $txtwordlist=""; for ($i=0;$i<count($long);$i++) { $txtwordlist.=$long[$i]['word'].' '; } $opmode="done"; $msg='I removed '.number_format($wordcount-$wordunique).' duplicate words from the list'; } ?> <html> <head> <title>Word Finder v1.00 by Zeb</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <div align="center"> <font style="font: 30px verdana; color: #ffffff; font-weight: bold;">Word Finder v1.00 by Zeb</font><br /><br /> <?php if (!empty($msg)) {echo "$msg<br /><br />";} else {echo "<br /><br />";} ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td valign="top" align="center"> <table cellspacing="0" cellpadding="2" class="outside"> <tr><td class="title">Enter the word list below</td></tr> <tr><td class="btextc"><textarea name="txtwordlist" class="textbox" cols="60" rows="20"><?=$txtwordlist?></textarea></td></tr> <tr><td class="btextc"><input type="submit" name="subsend" value="Submit List" class="button" /></td></tr> </table> </td> <td width="22"> </td> <td valign="top"> <table cellspacing="0" cellpadding="2" class="outside"> <tr><td class="title">The top 20 longest words are</td></tr> <?php if ($opmode=="done") { ?> <tr><td class="btext"><?=$topten?></td></tr> <?php } else { ?> <tr><td class="btextc">List yet to be generated</td></tr> <?php } ?> </table> </td> </tr> </table> </form> <?php $time_end=getmicrotime(); $time=$time_end-$time_start; ?> Page generated in <?=number_format($time,4)?> seconds </div> </body> </html> Sample data: http://www.pictureinthesky.net/utils/samplelist.txt If you copy and paste the sample list into the text box and click submit it takes a few seconds although I never get a value returned above 1.6 seconds. Any idea why? Quote Link to comment Share on other sites More sharing options...
fert Posted March 19, 2007 Share Posted March 19, 2007 Because it doesn't take more than 1.6 seconds for the script to execute Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 19, 2007 Author Share Posted March 19, 2007 Sorry I forgot to add the link to the script itself: http://www.pictureinthesky.net/utils/wordfinder.php Because it doesn't take more than 1.6 seconds for the script to execute So any idea how I can count how long it takes to sort the data? The only way I can think of is to use two scripts (recording the time then passing the data to the second script) but I'd rather not go that way. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 19, 2007 Author Share Posted March 19, 2007 Because it doesn't take more than 1.6 seconds for the script to execute Just read this again - it does - sometimes I'm sat here for around 10 seconds waiting for the page to be returned. Quote Link to comment Share on other sites More sharing options...
fert Posted March 19, 2007 Share Posted March 19, 2007 sometimes I'm sat here for around 10 seconds waiting for the page to be returned. That's most likely the time it takes to connect to the server, post the information and for the browser to parse the page Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 19, 2007 Author Share Posted March 19, 2007 Ah! Didn't consider that! Taking that on board I'm now a little happier knowing that my script is actually running quite quickly considering how much data I'm throwing at it. (JFI, it's to help me cheat at a word game. The game gives me a list of letters and I have to supply the longest word I can make from the given letters. I use a site to make anagrams [the long list] then I throw the generated list at my script) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.