Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x
Author Message
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1122

PostPosted: Sat Dec 14, 2013 5:11 am Reply with quote

From You Account module (RavenNuke 2.5+). I started today to check every single file and not happy Sad about it but of course Very Happy better than before. I decided to convert the whole module with commas and backticks and get rid of the unnecessaries echos. I have some little questions but first I will convert this file copyright.php to make sure it goes fine.

Code:
<?php

/**************************************************************************/
/* RN Your Account: Advanced User Management for RavenNuke
/* =======================================================================*/
/*
/* Copyright (c) 2008-2011, RavenPHPScripts.com   http://www.ravenphpscripts.com
/*
/* This program is free software. You can redistribute it and/or modify it
/* under the terms of the GNU General Public License as published by the
/* Free Software Foundation, version 2 of the license.
/*
/**************************************************************************/
/* RN Your Account is the based on:
/*  CNB Your Account http://www.phpnuke.org.br
/*  NSN Your Account by Bob Marion, http://www.nukescripts.net
/**************************************************************************/
$module_name = basename(dirname(__FILE__));
$mod_name = 'RN Your Account';
$author_email = '';
$author_homepage = 'http://www.ravenphpscripts.com';
$author_name = '<a href="http://rnwiki.ravennuke.com/wiki/RavenNuke2:Credits" target="_blank">RavenNuke Team</a>';
$license = 'GNU/GPL Copyright &copy; 2008-2011';
$download_location = '';
$module_version = '2.3.0';
$release_date = 'Aug 2008';
$module_description = '';
$mod_cost = '';
function show_copyright() {
   global $db, $ya_config, $mod_cost, $forum, $mod_name, $module_name, $release_date, $author_name, $author_email, $author_homepage, $license, $download_location, $module_version, $module_description;
   if (empty($mod_name)) {
      $mod_name = str_replace('_', ' ', $module_name);
   }
   echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
   echo '<html>';
   echo '<head>';
   echo '<title>' . $mod_name . ': Copyright Information</title>';
   echo '<style type="text/css">/*<![CDATA[*/';
   echo 'body {font-family:Verdana, Arial, Helvetica;font-size:10px;color:#363636;}';
   echo 'td {font-family:Verdana, Arial, Helvetica, geneva, sans-serif;font-size:10px;color:#000000;}';
   echo '/*]]>*/</style>';
   echo '</head>';
   echo '<body bgcolor="#FFFFFF" link="#000000" alink="#000000" vlink="#000000" style="margin:0;">';
   echo '<table align="center" border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
   echo '<td width="100%" align="center">';
   echo '<span style="font-weight:bold;">Module Copyright &copy; Information</span><br />';
   echo $mod_name . ' module for <a href="http://www.ravennuke.com" target="_blank">RavenNuke&trade;</a>';
   echo '</td></tr></table>';
   echo '<div style="text-align:center;">';
   echo '<img src="images/arrow.png" border="0" alt="" />&nbsp;';
   echo '<a href="credits.html" title="Click To View The RN Your Account Credits Page" target="_blank">';
   echo '<span style="color:#E66C2C;font-weight:bold;">View RN Your Account Credits &amp; Contacts</span></a>&nbsp;';
   echo '<img src="images/arrow2.png" border="0" alt="" />';
   echo '</div>';
   echo '<hr />';
   echo '<table align="center" border="0" cellspacing="0" cellpadding="2" width="100%">';
   if ($mod_name != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Name:</span></td><td>' . $mod_name . '</td></tr>';
   }
   if ($module_version != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Version:</span></td><td>' . $module_version . '</td></tr>';
   }
   if ($release_date != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Release Date:</span></td><td>' . $release_date . '</td></tr>';
   }
   if ($mod_cost != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Cost:</span></td><td>' . $mod_cost . '</td></tr>';
   }
   if ($license != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">License:</span></td><td>' . $license . '</td></tr>';
   }
   if ($author_name != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Author's Name:</span></td><td>' . $author_name . '</td></tr>';
   }
   if ($author_email != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Author's Email:</span></td><td>' . $author_email . '</td></tr>';
   }
   if ($module_description != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Description:</span></td><td>' . $module_description . '</td></tr>';
   }
   if ($download_location != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Download:</span></td><td><a href="' . $download_location . '" target="_blank">Download</a></td></tr>';
   }
   echo '</table>';
   echo '<hr />';
   echo '<div style="text-align:center;">[ <a href="javascript:void(0)" onclick=\'javascript:self.close()\'>Close Window</a> ]</div>';
   echo '</body>';
   echo '</html>';
}
show_copyright();
?>


New One

Code:
<?php

/**************************************************************************/
/* RN Your Account: Advanced User Management for RavenNuke
/* =======================================================================*/
/*
/* Copyright (c) 2008-2011, RavenPHPScripts.com   http://www.ravenphpscripts.com
/*
/* This program is free software. You can redistribute it and/or modify it
/* under the terms of the GNU General Public License as published by the
/* Free Software Foundation, version 2 of the license.
/*
/**************************************************************************/
/* RN Your Account is the based on:
/*  CNB Your Account http://www.phpnuke.org.br
/*  NSN Your Account by Bob Marion, http://www.nukescripts.net
/**************************************************************************/
$module_name = basename(dirname(__FILE__));
$mod_name = 'RN Your Account';
$author_email = '';
$author_homepage = 'http://www.ravenphpscripts.com';
$author_name = '<a href="http://rnwiki.ravennuke.com/wiki/RavenNuke2:Credits" target="_blank">RavenNuke Team</a>';
$license = 'GNU/GPL Copyright &copy; 2008-2011';
$download_location = '';
$module_version = '2.3.0';
$release_date = 'Aug 2008';
$module_description = '';
$mod_cost = '';
function show_copyright() {
   global $db, $ya_config, $mod_cost, $forum, $mod_name, $module_name, $release_date, $author_name, $author_email, $author_homepage, $license, $download_location, $module_version, $module_description;
   if (empty($mod_name)) {
      $mod_name = str_replace('_', ' ', $module_name);
   }
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' , PHP_EOL
   , '<html xmlns="http://www.w3.org/1999/xhtml">' , PHP_EOL
   , '<head>' . PHP_EOL
   , '<title>' , $mod_name , ': Copyright Information</title>' , PHP_EOL
   , '<style type="text/css">/*<![CDATA[*/' , PHP_EOL
   , 'body {font-family:Verdana, Arial, Helvetica;font-size:10px;color:#363636;}' , PHP_EOL
   , 'td {font-family:Verdana, Arial, Helvetica, geneva, sans-serif;font-size:10px;color:#000000;}' , PHP_EOL
   , '/*]]>*/</style>' , PHP_EOL
   , '</head>' , PHP_EOL
   , '<body bgcolor="#FFFFFF" link="#000000" alink="#000000" vlink="#000000" style="margin:0;">' , PHP_EOL
   , '<table align="center" border="0" cellspacing="0" cellpadding="0" width="100%"><tr>' , PHP_EOL
   , '<td width="100%" align="center">' , PHP_EOL
   , '<span style="font-weight:bold;">Module Copyright &copy; Information</span><br />' , PHP_EOL
   , $mod_name , ' module for <a href="http://www.ravennuke.com" target="_blank">RavenNuke&trade;</a>' , PHP_EOL
   , '</td></tr></table>' , PHP_EOL
   , '<div style="text-align:center;">' , PHP_EOL
   , '<img src="images/arrow.png" border="0" alt="" />&nbsp;' , PHP_EOL
   , '<a href="credits.html" title="Click To View The RN Your Account Credits Page" target="_blank">' , PHP_EOL
   , '<span style="color:#E66C2C;font-weight:bold;">View RN Your Account Credits &amp; Contacts</span></a>&nbsp;' , PHP_EOL
   , '<img src="images/arrow2.png" border="0" alt="" />' , PHP_EOL
   , '</div>' , PHP_EOL
   , '<hr />' , PHP_EOL
   , '<table align="center" border="0" cellspacing="0" cellpadding="2" width="100%">' , PHP_EOL;
   if ($mod_name != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Name:</span></td><td>' , $mod_name , '</td></tr>' , PHP_EOL;
   }
   if ($module_version != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Version:</span></td><td>' , $module_version , '</td></tr>' , PHP_EOL;
   }
   if ($release_date != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Release Date:</span></td><td>' , $release_date , '</td></tr>' , PHP_EOL;
   }
   if ($mod_cost != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Cost:</span></td><td>' , $mod_cost , '</td></tr>' , PHP_EOL;
   }
   if ($license != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">License:</span></td><td>' . $license . '</td></tr>';
   }
   if ($author_name != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Author's Name:</span></td><td>' , $author_name , '</td></tr>' , PHP_EOL;
   }
   if ($author_email != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Author's Email:</span></td><td>' . $author_email . '</td></tr>' , PHP_EOL;
   }
   if ($module_description != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Description:</span></td><td>' , $module_description , '</td></tr>' , PHP_EOL;
   }
   if ($download_location != '') {
      echo '<tr><td nowrap="nowrap"><img src="images/arrow.png" border="0" alt="" />&nbsp;<span style="font-weight:bold;">Module's Download:</span></td><td><a href="' , $download_location , '" target="_blank">Download</a></td></tr>' , PHP_EOL;
   }
echo '</table>' , PHP_EOL
   , '<hr />' , PHP_EOL
   , '<div style="text-align:center;">[ <a href="javascript:void(0)" onclick=\'javascript:self.close()\'>Close Window</a> ]</div>' , PHP_EOL
   , '</body>' , PHP_EOL
   , '</html>' , PHP_EOL;
}
show_copyright();


Note: If you see any mistake in order to improve this file please, report it asap.
 
View user's profile Send private message
djmaze
Subject Matter Expert



Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv

PostPosted: Sat Dec 14, 2013 10:34 am Reply with quote

PHP_EOL? Is that really necessary?
 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Sat Dec 14, 2013 6:48 pm Reply with quote

This is not about PHP_EOL but in case u are intesting here I show u the link.
[ Only registered users can see links on this board! Get registered or login! ]
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Sat Dec 14, 2013 8:40 pm Reply with quote

<getting the popcorn ready>
 
View user's profile Send private message Send e-mail
djmaze







PostPosted: Sun Dec 15, 2013 6:08 am Reply with quote

hicuxunicorniobestbuildpc wrote:
This is not about PHP_EOL but in case u are intesting here I show u the link.

Bad example but, ok it's free to do so.
[ Only registered users can see links on this board! Get registered or login! ]
Quote:
The correct 'End Of Line' symbol for this platform. Available since PHP 4.3.10 and PHP 5.0.2

It is used for writing files to the platform in use.
When your server is Unix the EOL is "\n", on Windows it is "\r\n".
Good examples are log files.

Sending HTML or E-mail it is of no use at all Wink
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sun Dec 15, 2013 7:44 am Reply with quote

djmaze wrote:
Sending HTML or E-mail it is of no use at all Wink


I completely agree with you dj. If I need to debug the html, a simple browser extension does it for me with a click of a button. To me, it is just extra code to have to write and be parsed, but I know some like to see nicely formatted HTML when they view the source.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Sun Dec 15, 2013 8:58 am Reply with quote

Thanks for your info djmaze but this post is not about PHP_EOL. Like this we go to another direction.

Quote:
I decided to convert the whole module with commas and backticks and get rid of the unnecessaries echos
 
Guardian2003







PostPosted: Sun Dec 15, 2013 1:03 pm Reply with quote

hicuxunicorniobestbuildpc wrote:
Thanks for your info djmaze but this post is not about PHP_EOL. Like this we go to another direction.

Quote:
I decided to convert the whole module with commas and backticks and get rid of the unnecessaries echos

Well it kinda is about PHP_EOL since you asked
Quote:
Note: If you see any mistake in order to improve this file please, report it asap.


What is your objective with regard to "improve this file"?

You are re-writing the file using the comma for echo'd string concatenation (because it is marginally faster then using the method in the original file) so I think it is reasonable for to deduce that your changes are for the sake of parsing efficiency.

djmaze asked a simple question pertaining to your changes
Quote:
PHP_EOL? Is that really necessary?

If your objective is one of parsing efficiency, then PHP_EOL is not needed and using it as you have done probably increases the time taken to parse the file.

If your objective was for readability of the rendered HTML in the browser, then the use of PHP_EOL might be considered necessary - but is this more efficient than using the more conventional \n\r ?

As we have discussed here many, many times before, there are numerous ways to "improve" code but concentrating on one specific area, usually compromises another area.
You are free to change RavenNuke(tm) code to suit your own needs, for your personal use but there really isn't any need to make a post every time you change a file unless you have found a bug in the unchanged code.
 
hicuxunicorniobestbuildpc







PostPosted: Mon Dec 16, 2013 4:22 am Reply with quote

Quote:
You are re-writing the file using the comma for echo'd string concatenation (because it is marginally faster then using the method in the original file)


Yes, I do want that and I just wanted to show the old code which in my opinion it should be already changed. I thought it will be wise to share some changes.

For example:

If we are running HTML 4.01 in one of the files from RavenNuke

Code:
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';


instead of replacing with:

Code:
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' , PHP_EOL


or

Code:
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'


Why does every time come a new version we need to see the same old code? Are we affraid of CHANGE?

Yesterday I checked almost all the files from Your Account module and I found this line.

Code:
// Added login option to registration

global $stop, $module_name, $redirect, $mode, $unwatch, $t, $f, $p, $ya_config;
   if (!is_user($user)) {
      mt_srand((double)microtime() * 1000000);
      $maxran = 10000000;
      $random_num = mt_rand(0, $maxran);
      
      echo '<form action="modules.php?name=' . $module_name . '" method="post">';
      echo '<table border="0">';
      echo '<tr><td>' . _NICKNAME . ':</td><td><input type="text" name="username" size="15" maxlength="25" /></td></tr>';
      echo '<tr><td>' . _PASSWORD . ':</td><td><input type="password" name="user_password" size="15" maxlength="20" /></td></tr>';
      echo '<tr><td colspan="2">' . security_code(array(2, 4, 5, 7) , 'stacked') . '</td></tr>';
      echo '<tr><td>';
      echo '<input type="hidden" name="random_num" value="' . $random_num . '" />';
      echo '<input type="hidden" name="redirect" value="' . $redirect . '" />';
      echo '<input type="hidden" name="mode" value="' . $mode . '" />';
      echo '<input type="hidden" name="unwatch" value="' . $unwatch . '" />';
      echo '<input type="hidden" name="f" value="' . $f . '" />';
      echo '<input type="hidden" name="t" value="' . $t . '" />';
      echo '<input type="hidden" name="p" value="' . $p . '" />';
      echo '<input type="hidden" name="op" value="login" />';
      echo '<input type="submit" value="' . _LOGIN . '" />';
      if ($ya_config['useactivate'] == 1) {
         echo '<br />(' . _BESUREACT . ')';
      }
      echo '</td></tr></table></form><br />';
      } elseif (is_user($user)) {
      global $cookie;
      cookiedecode($user);
      Header('Location: modules.php?name=' . $module_name . '&op=userinfo&username=' . $cookie[1]);
   }
// End login option to registration


I changed it like this

Code:
      echo '<form action="modules.php?name=' , $module_name , '" method="post">' , PHP_EOL

      , '<table border="0">' , PHP_EOL
      , '<tr><td>' , _NICKNAME , ':</td><td><input type="text" name="username" size="15" maxlength="25" /></td></tr>' , PHP_EOL
      , '<tr><td>' , _PASSWORD , ':</td><td><input type="password" name="user_password" size="15" maxlength="20" /></td></tr>' , PHP_EOL
      , '<tr><td colspan="2">' , security_code(array(2, 4, 5, 7) , 'stacked') , '</td></tr>' , PHP_EOL
      , '<tr><td>' , PHP_EOL
      , '<input type="hidden" name="random_num" value="' , $random_num , '" />' , PHP_EOL
      , '<input type="hidden" name="redirect" value="' , $redirect , '" />' , PHP_EOL
      , '<input type="hidden" name="mode" value="' , $mode , '" />' , PHP_EOL
      , '<input type="hidden" name="unwatch" value="' , $unwatch , '" />' , PHP_EOL
      , '<input type="hidden" name="f" value="' , $f , '" />' , PHP_EOL
      , '<input type="hidden" name="t" value="' , $t , '" />' , PHP_EOL
      , '<input type="hidden" name="p" value="' , $p , '" />' , PHP_EOL
      , '<input type="hidden" name="op" value="login" />' , PHP_EOL
      , '<input type="submit" value="' , _LOGIN , '" />' , PHP_EOL;
      if ($ya_config['useactivate'] == 1) {
         echo '<br />(' , _BESUREACT , ')' , PHP_EOL;
      }
      echo '</td></tr></table></form><br />' , PHP_EOL;
      } elseif (is_user($user)) {
      global $cookie;
      cookiedecode($user);
      Header('Location: modules.php?name=' . $module_name . '&op=userinfo&username=' . $cookie[1]);
   }
// End login option to registration


but since u think
Code:
' , PHP_EOL;
is not necessary then I will use it like this because it is faster.

Code:
      echo '<form action="modules.php?name=' , $module_name , '" method="post">'

      , '<table border="0">'
      , '<tr><td>' , _NICKNAME , ':</td><td><input type="text" name="username" size="15" maxlength="25" /></td></tr>'
      , '<tr><td>' , _PASSWORD , ':</td><td><input type="password" name="user_password" size="15" maxlength="20" /></td></tr>'
      , '<tr><td colspan="2">' , security_code(array(2, 4, 5, 7) , 'stacked') , '</td></tr>'
      , '<tr><td>'
      , '<input type="hidden" name="random_num" value="' , $random_num , '" />'
      , '<input type="hidden" name="redirect" value="' , $redirect , '" />'
      , '<input type="hidden" name="mode" value="' , $mode , '" />'
      , '<input type="hidden" name="unwatch" value="' , $unwatch , '" />'
      , '<input type="hidden" name="f" value="' , $f , '" />'
      , '<input type="hidden" name="t" value="' , $t , '" />'
      , '<input type="hidden" name="p" value="' , $p , '" />'
      , '<input type="hidden" name="op" value="login" />'
      , '<input type="submit" value="' , _LOGIN , '" />';
      if ($ya_config['useactivate'] == 1) {
         echo '<br />(' , _BESUREACT , ')';
      }
      echo '</td></tr></table></form><br />';
      } elseif (is_user($user)) {
      global $cookie;
      cookiedecode($user);
      Header('Location: modules.php?name=' . $module_name . '&op=userinfo&username=' . $cookie[1]);
   }
// End login option to registration


It is the same if we have an old pair of srunning shoes and every time we need to repair it and at the end with the money u spent all the time u can buy a nice new pair of shoes. Very Happy

but to be clear I want to know what is better and fastest to use for the future?

Should I always use single-quotes for PHP strings?

Note: After all these changes I noticed my site loads really fast. Running CSS instead of .png or .gif images are giving me nice results. Thanks for all information guys.
Very Happy
 
Guardian2003







PostPosted: Mon Dec 16, 2013 7:56 am Reply with quote

Yes, you are perfectly correct when you say our existing code should already be changed and for the most part it is. Unfortunately we only have a limited number of RN Team members and individually, they only have a limited amount of free time.
There are so many changes between RavenNuke(tm) 2.5.1 and what is coming next that what he had planned to release as RavenNuke(tm) 3 is now a completely different product (RavenCMS (tm)).

Nice to hear your website is running faster, it is good experience to tinker with code.

Yes single quotes are faster. echoing around 10k lines you'll save around 1 millionth of a second. Here is some POC code taken from the StackOverflow ebsite
Code:


function timeFunc($function, $runs)
{
  $times = array();

  for ($i = 0; $i < $runs; $i++)
  {
    $time = microtime();
    call_user_func($function);
    $times[$i] = microtime() - $time;
  }

  return array_sum($times) / $runs;
}

function Method1()
{
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are $foo";
}

function Method2()
{
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are {$foo}";
}

function Method3()
 {
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are " . $foo;
}

print timeFunc('Method1', 10) . "\n";
print timeFunc('Method2', 10) . "\n";
print timeFunc('Method3', 10) . "\n";

My results for this test after running the code several times are;
0.0009019
0.0009157
0.0007183
 
hicuxunicorniobestbuildpc







PostPosted: Mon Dec 16, 2013 9:59 am Reply with quote

I runned your example as well a couple of times and my result was

0.0013769
0.0013747
0.0010182

Very Happy

so this method 3 is the fastest.

Code:
function Method3()

 {
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are " . $foo;
}


How can I convert this method 3 to use echo? I want to use comma. Why I can not use comma in this example?

Code:
function Method3()

 {
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are " , $foo;
}



I can not use a comma. I get an error.

Parse error: syntax error, unexpected ',' in

Is there any other method to make method 3 with echo so I can use comma?
 
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1772

PostPosted: Wed Dec 18, 2013 3:39 pm Reply with quote

hicuxunicorniobestbuildpc, quick and simply - there is NO other method! :clap:

_________________
Github: RavenNuke 
View user's profile Send private message
djmaze







PostPosted: Thu Dec 19, 2013 4:52 pm Reply with quote

hicuxunicorniobestbuildpc wrote:
so this method 3 is the fastest.

And you think that is the fastest? try:
Code:
function Method4()

{
    $foo = 'some words';
    for ($i = 0; $i < 10000; $i++)
        $t = "these are {$foo}";
}
[ Only registered users can see links on this board! Get registered or login! ]
 
hicuxunicorniobestbuildpc







PostPosted: Thu Dec 19, 2013 5:30 pm Reply with quote

nee your method 4 is not faster than method 3

U can see by yourself.
[ Only registered users can see links on this board! Get registered or login! ]

Your page is giving me 1 validation warning from

Code:
<code>foreach ($array as &$v)</code>


Shoundn't be

Code:
<code>foreach ($array as &amp; $v)</code>


or

Code:
<code>foreach ($array as & $v)</code>


Note: It is coming from
Code:
Loop a numerical indexed Array of Strings


Here I show u the whole script so u can follow the methods and u understand who is method 4 which should be the last one.

Code:
<?php


function timeFunc($function, $runs)
{
  $times = array();

  for ($i = 0; $i < $runs; $i++)
  {
    $time = microtime();
    call_user_func($function);
    $times[$i] = microtime() - $time;
  }

  return array_sum($times) / $runs;
}

function Method1()
{
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are $foo";
}

function Method2()
{
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are {$foo}";
}

function Method3()
 {
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are " . $foo;
}
function Method4()
{
    $foo = 'some words';
    for ($i = 0; $i < 10000; $i++)
        $t = "these are {$foo}";
}
print timeFunc('Method1', 10) . "\n";
print timeFunc('Method2', 10) . "\n";
print timeFunc('Method3', 10) . "\n";
print timeFunc('Method4', 10) . "\n";
 
hicuxunicorniobestbuildpc







PostPosted: Thu Dec 19, 2013 5:45 pm Reply with quote

I found out your method 4 is exactly the same as method 2 so please tell me what is coming new?

Code:
function Method2()

{
  $foo = 'some words';
  for ($i = 0; $i < 10000; $i++)
    $t = "these are {$foo}";
}


I don't see any different from this method 4

Code:
function Method4()

{
    $foo = 'some words';
    for ($i = 0; $i < 10000; $i++)
        $t = "these are {$foo}";
}


Shocked Very Happy
 
djmaze







PostPosted: Fri Dec 20, 2013 6:18 am Reply with quote

My bad, i misread method2. It is the same.
On my machine #2 is faster then #3 though Smile

The conclusion is that the speed differs per machine, PHP version and machine load.
So there is no real good speed improvement noticeable and you should not alter it.

MySQL is the real slow down and query optimization is the thing to worry about.

Another thing is the PHPBB code itself. Just by modifying a few lines of the code i improved speed by 33%. [ Only registered users can see links on this board! Get registered or login! ]
 
hicuxunicorniobestbuildpc







PostPosted: Fri Dec 20, 2013 9:47 am Reply with quote

at first site I noticed something

Slow
Code:
$end_counter--;


Fast
Code:
--$end_counter;


This is a very nice example but my question is: Are all programmers or coders going to follow the same rule? It will be nice if everybody do the same so we can get a nice result in the future.

My bad, i misread method2. It is the same.
On my machine #2 is faster then #3 though Smile

Quote:
The conclusion is that the speed differs per machine, PHP version and machine load.
This is true but we are not talking about if you have a Pentium 3 or I have Pentium 5. If we have both the same server and the same processor then u see that old code will always be slowly.

Quote:
So there is no real good speed improvement noticeable and you should not alter it.
This is not true and I disagree with you.

Quote:

Another thing is the PHPBB code itself. Just by modifying a few lines of the code i improved speed by 33%. [ Only registered users can see links on this board! Get registered or login! ]
You actually agree so it is true.

Very Happy
 
djmaze







PostPosted: Sat Dec 21, 2013 5:06 am Reply with quote

hicuxunicorniobestbuildpc wrote:

Quote:

Another thing is the PHPBB code itself. Just by modifying a few lines of the code i improved speed by 33%. [ Only registered users can see links on this board! Get registered or login! ]
You actually agree so it is true.

Partially. If there is a difference in what to optimize.
 
Guardian2003







PostPosted: Sun Dec 22, 2013 6:45 am Reply with quote

hicuxunicorniobestbuildpc wrote:
This is a very nice example but my question is: Are all programmers or coders going to follow the same rule? It will be nice if everybody do the same so we can get a nice result in the future.

The answer to that is NO. Different people have different hand writing and it's the same when you write PHP code. Different people have different styles.
For the RN Team, we have specific coding standards which we try to stick to so that the code looks consistent throughout the CMS. However, some modules are/were developed and released by individuals and then incorporated or modified for inclusion into the CMS later on, which is why you might see inconsistencies like multiple lines of echo statements instead of one long concatenated string or using the period instead of the comma for concatenated echo's.

Obviously some 'styles' are more efficient in terms of resource usage than others but at the same time (as we have discussed before), sometimes that infinitesimal advantage has a negative effect somewhere else, maybe code readability or maybe rendered html readability.

To emphasis one type of code readability, look at if/else statements
Code:
$var = $action == 'edit' ? 'Edit' : ($action == 'delete' ? 'Delete' : 'New');

Is that completely understandable to a novice PHP coder?
 
montego







PostPosted: Sun Dec 22, 2013 7:14 am Reply with quote

Yes, please keep in mind that none of us are paid here and there aren't even enough donations to keep the infrastructure costs from chewing into Raven's own pocket each month.

Hey, if anyone out there has loads of extra cash on hand and can pay to have a group of experienced PHP/MySQL programmers work full time on this project and feed their families at the same time, we'd love to hear from you. Laughing
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sat Dec 28, 2013 2:26 am Reply with quote

hicuxunicorniobestbuildpc,

The bottom line is we won't be changing any code for the sake of changing code. It is what it is, basically, until v3.0 is released and even then, for a saving of .003 seconds is NOT worth the effort to do so. Let's be real about this Bang Head

Topic locked!
 
View user's profile Send private message
Display posts from previous:       
Post new topic   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©