Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 12th, 2005, 08:33 PM
rApid rApid is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 rApid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to rApid
Help 2 Optmize This Script!

I know people say using print rather then echo, and things like object instead of array is faster, but could someone please take this console script, and optmize it as fast as it can be made, by using print and object, and other things to make load times as fast as possible.

php Code:
Original - php Code
  1.  
  2.  function dispConsole()
  3. {
  4.          global $row1, $row2, $bgimg, $consolesep;
  5.  
  6.          {
  7.         dispProfile();
  8. echo ' Welcome to Your Console '.$_SESSION['rank'].' '.$_SESSION['username'].'
  9.         ';
  10. $result1=mysql_query("SELECT * FROM consoles WHERE minrank<= '".$_SESSION['rank']."' AND disabled=0  ORDER BY position ASC");
  11.  while($row2 = mysql_fetch_object($result1)) {
  12.  
  13.  
  14.                 echo '
  15.                 <div align='center'>
  16.          <table width=85%>
  17.           <tr class='row1'>';
  18.            echo "<td background=$bgimg width=75%>";echo '<u>'.$GLOBALS['consolecolor'].' '; echo " $row2->name "; echo ' </font></u></td>
  19.           </tr>
  20.           <tr class='row2'>
  21.             <td align='center'>
  22. ';
  23.  
  24.  
  25.  $result = mysql_query("SELECT * FROM consolestuff WHERE minrank<= '".$_SESSION['rank']."' AND console ="$row2->name"");
  26.  
  27.  while($row3 = mysql_fetch_object($result)) {
  28.  
  29. echo " $consolesep <a href=$row3->link> $row3->name</a> "; } echo '   $consolesep
  30.   </td>
  31.           </tr>
  32.         </table>
  33.         </div>
  34.      ';
  35.      //viewNews(1);
  36. }        } }
  37.  



any help would be great, i would like to see how some of you code compared to me, and if it is a faster way of coding the same script, i'd love to use your way instead!

Reply With Quote
  #2  
Old April 12th, 2005, 08:44 PM
System System is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Posts: 665 System User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Message Moved

Thread moved from 'PHP Coding' to 'Programming Theory' by andrew.

Reason:

Reply With Quote
  #3  
Old April 12th, 2005, 10:58 PM
lig's Avatar
lig lig is offline
"Forum Nazi"
Codewalkers Demi-God (4500 - 4999 posts)
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,727 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 1 h 4 m 45 sec
Reputation Power: 6
RE: Help 2 Optmize This Script!

As far as I know echo vs. print has little to no difference in speed. Arrays vs. Objects = As far as I know they are also reletively comparitable - though I beleive arrays take up less space (don't bet the farm on that though).

One thing I did notice is that you use double quotes occasionally. singles are faster. Also you echo out HTML - you can just open and close your php instead, especially for relatively "large" blocks of HTML. And I personally don't like using globals. If my functions needs something I pass it - but that is more a coding style.

Well that is my $0.02. Take it or leave it. Oh and if you are really worried about speed - time your scripts with different variations. Then you will know if the script is the fastest it can be.

Reply With Quote
  #4  
Old April 15th, 2005, 12:10 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Help 2 Optmize This Script!

I wouldnt call it exactly..speeding up your script, but cleaning it up may be a better word for it.

Take for instance this part:

php Code:
Original - php Code
  1.  
  2.  
  3.  echo '
  4.                 <div align='center'>
  5.          <table width=85%>
  6.           <tr class='row1'>';
  7.            echo "<td background=$bgimg width=75%>";echo '<u>'.$GLOBALS['consolecolor'].' '; echo " $row2->name "; echo ' </font></u></td>
  8.           </tr>
  9.           <tr class='row2'>
  10.             <td align='center'>
  11. ';


What I normally try to do, is keep all HTML stuff in one organized area. This can be accomplished as:

php Code:
Original - php Code
  1.  
  2. $_mydivide= <<<EOD
  3.  <div align='center'>
  4.          <table width=85%>
  5.           <tr class='row1'>
  6.           <td background=$bgimg width=75%><font>$_mystatement </font></u></td>
  7.           </tr>
  8.           <tr class='row2'>
  9.             <td align='center'>
  10.  
  11. EOD;


Than, to call it all out, you could go about doing this:

php Code:
Original - php Code
  1.  
  2. $_mystatement="<u>'.$GLOBALS['consolecolor'].' $row2->name";
  3. print("$_mydivide");


Just with that tidbit, you can dramatically cut down your lines of code.
So, lets just apply that bit of it to your script.

php Code:
Original - php Code
  1.  
  2.  
  3.     function dispConsole()
  4.     {
  5.              global $row1, $row2, $bgimg, $consolesep;
  6.  
  7.              {
  8.             dispProfile();
  9.     echo ' Welcome to Your Console '.$_SESSION['rank'].' '.$_SESSION['username'].'
  10.             ';
  11.     $result1=mysql_query("SELECT * FROM consoles WHERE minrank<= '".$_SESSION['rank']."' AND disabled=0  ORDER BY position ASC");
  12.     while($row2 = mysql_fetch_object($result1)) {
  13.  
  14. //your statement can now be modified on the fly if need be
  15.  
  16. $_mystatement="<font><u>'.$GLOBALS['consolecolor'].' $row2->name</font></u>";
  17.  
  18. //here we have your table output
  19. $_mydivide = <<<EOD
  20.  <div align='center'>
  21.          <table width=85%>
  22.           <tr class='row1'>
  23.           <td background=$bgimg width=75%>$_mystatement</td>
  24.           </tr>
  25.           <tr class='row2'>
  26.             <td align='center'>
  27.  
  28. EOD;
  29.  
  30. // this prints out your information and table from one simple call line.
  31.  
  32. print("$_mydivide");
  33.  
  34.     $result = mysql_query("SELECT * FROM consolestuff WHERE minrank<= '".$_SESSION['rank']."' AND console ="$row2->name"");
  35.  
  36.     while($row3 = mysql_fetch_object($result)) {
  37.  
  38.     echo " $consolesep <a href=$row3->link> $row3->name</a> "; } echo '   $consolesep
  39.       </td>
  40.               </tr>
  41.             </table>
  42.             </div>
  43.          ';
  44.          //viewNews(1);
  45.     }        } }
  46.     ?>
  47.  
  48.  


Without knowing how this actually executes, or what info you pull up when running that script, it is possible that this will not work within the function guideline, however, it is the little tweaks like that above (and one could be made for your other echo statement as a link function) which keep (in my opinion anyway) things nice and easy to configure and edit down the road. Of course, a person could make one whole class out of that statement as well, but for now, as a function, it might do the trick.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesProgramming Theory > Help 2 Optmize This Script!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway