SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast z00om's Avatar
    Join Date
    Dec 2001
    Location
    California
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Test your code...

    I know I will probably get like a bazillion people breathing down my neck and coughing at EVERY MISTEAK, but here is a little (hah) bit of code that'll allow you to input two different peices of code (PHP), then press the button and it will compare the two different bits of code and tell you which is faster... if you just want to time one block of code put it in twice

    PHP Code:
    <?php
    function doTop() {
    ?>
    <html>
    <head>
    <style>
        .txt {
            font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
            font-size: 11px;
            color: #000;
        }
    </style>
    </head>
    <body>
    <?php
    }

    if ( !isset(
    $_GET['action']) && !isset($_POST['action']) )
    {
        
    doTop();
    ?>
    <table bgcolor="#ffffff" width="650" height="100%" align="center" border="0" cellpadding="0" cellspacing="0">
     <tr bgcolor="#ffffff">
      <td bgcolor="#ffffff" width="650" align="left" valign="middle">
       <span class="txt">Simply enter in two different peices of code (usually two different peices of code that do the same thing) and they will both be performed, and tested. Please remember, this script is simply for the purpose of comparison as the code you enter will be inserted into an eval() function, which will add slightly to the execution time.</span><br /><br />
       <form method="post" action="<?php echo $PHP_SELF?>">
       <input type="hidden" name="action" value="Execute">
       <table bgcolor="#000000" width="650" align="center" border="0" cellpadding="4" cellspacing="1">
        <tr bgcolor="#ffffff">
         <td bgcolor="#f1f1f1" colspan="2" align="left"><span class="txt">PHP Code Comparison Analyzer</span></td>
        </tr>
        <tr bgcolor="#ffffff">
         <td bgcolor="#ffffff" width="100" align="left" valign="top"><span class="txt">First Piece of Code:</span></td>
         <td bgcolor="#cecece" width="550" align="center"><textarea name="code1" rows="10" cols="62"></textarea>
        </tr>
        <tr bgcolor="#ffffff">
         <td bgcolor="#ffffff" width="100" align="left" valign="top"><span class="txt">Second Piece of Code:</span></td>
         <td bgcolor="#cecece" width="550" align="center"><textarea name="code2" rows="10" cols="62"></textarea>
        </tr>
        <tr bgcolor="#ffffff">
         <td bgcolor="#cecece" colspan="2" height="27" align="center">
          <input type="submit" value="  Test!  " />
         </td>
        </tr>
       </table>
       </form>
      </td>
     </tr>
    </table>
    <?php
    }
    else
    {
        if ( !isset(
    $_GET['action']) )
        {
            echo 
    "<html>\n";
            echo 
    "<body>\n";
            echo 
    "<!-- \n\n";
            
    $start microtime();
            eval(
    stripslashes($_POST['code1']));
            
    $end microtime();
            echo 
    "\n\n -->\n";
            echo 
    '<script language="JavaScript">'."\n".'document.location = "'.$PHP_SELF.'?action=doNext&time1='.$start.'&time2='.$end.'&code1='.$_POST['code1'].'&code2='.$_POST['code2'].'";'."\n".'</script>'."\n".'</body>'."\n".'</html>';
        }
        else if ( 
    $_GET['action'] == "doNext" )
        {
            echo 
    "<html>\n";
            echo 
    "<body>\n";
            echo 
    "<!-- \n\n";
            
    $start microtime();
            eval(
    stripslashes($_GET['code2']));
            
    $end microtime();
            echo 
    "\n\n -->\n";
            echo 
    '<script language="JavaScript">'."\n".'document.location = "'.$PHP_SELF.'?action=Finish&time1='.$_GET['time1'].'&time2='.$_GET['time2'].'&code1='.$_GET['code1'].'&time3='.$start.'&time4='.$end.'&code2='.$_GET['code2'].'";'."\n".'</script>'."\n".'</body>'."\n".'</html>';
        }
        else
        {
            
    doTop();
    ?>
    <span class="txt">Below are the results of your codes execution...<br /><br /><br /><br />
    <b>First</b> code block:
    <pre>
    <?php echo stripslashes($_GET['code1']); ?>
    </pre>
    Codes execution time: <?php echo ($_GET['time2'] - $_GET['time1']); ?>
    <br /><br /><br />
    <b>Second</b> code block:
    <pre>
    <?php echo stripslashes($_GET['code2']); ?>
    </pre>
    Codes execution time: <?php echo ($_GET['time4'] - $_GET['time3']); ?>
    <br /><br /><br />
    <b>Final Results</b>:<br />
    <?php
            
    echo "The <b>";
            if ( (
    $_GET['time2'] - $_GET['time1']) < ($_GET['time4'] - $_GET['time3']) )
            {
                echo 
    "first";
                
    $final $_GET['time2'] - $_GET['time1'];
            }
            else
            {
                echo 
    "second";
                
    $final $_GET['time4'] - $_GET['time3'];
            }
            echo 
    "</b> code block was faster by ".$final." seconds.<br /><br /><br />";
            echo 
    '<a href="'.$PHP_SELF.'">Do it again!</a>'."\n";
            echo 
    "</span>\n";
        }
    }
    ?>
    </body>
    </html>
    Legal notice: I (Scott Roberts) take NO liability for any effects of this script. The consequences of this script are your own liability, and this script is offered WITHOUT WARRANY. And I cannot be held accountable for any of the effects of this script.

    PASSWORD PROTECT or HIDE this script! And I suggest you DON'T leave it on your server. This script can pose a large security risk, and it is suggested it only be put anywhere it may be executed only for short periods of time in a password protected directory.
    Last edited by z00om; Apr 8, 2002 at 01:15.
    [z00om : home]
    [z00om@hotmail.com]
    [z00om : aim]
    [77968493 : icq]

  2. #2
    SitePoint Enthusiast z00om's Avatar
    Join Date
    Dec 2001
    Location
    California
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NOTE:

    THIS SCRIPT will pose a VERY DANGEOUS security hazzard!

    DO NOT ALLOW ANYONE BUT YOU AND THOSE YOU TRUST ACCESS!

    I take NO RESPONSABILITY for ANY effects and offer this script WITHOUT WARRANTY. ANY DAMAGE is your own sole liability, and I will not take any fault for the consequences of using this script.

    Basically--you're on your own, and DON'T let anyone else see it!
    [z00om : home]
    [z00om@hotmail.com]
    [z00om : aim]
    [77968493 : icq]

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmmm

    I tried test this script to see what the fuss was about, but all i seem to get is unterminated string, due to this

    PHP Code:

    <html>
    <body>
    <!-- 

    <br>
    <b>Parse error</b>:  parse error in <b>c:\program files\apache group\apache\htdocs\t.php3(60) : eval()'d code</b> on line <b>1</b><br>


     -->
    <script language="JavaScript">
    document.location = "/t.php3?action=doNext&time1=0.43608000 1018252063&time2=0.43620500 1018252063&code1=<?
    echo \'test\';
    ?>&code2=<?
    echo \'test\';
    ?>";
    </script>
    </body>
    </html></body>
    </html>
    on the new page?

  4. #4
    SitePoint Enthusiast z00om's Avatar
    Join Date
    Dec 2001
    Location
    California
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that means the code you put in isn't valid...

    hint: do not put <?php ?>
    [z00om : home]
    [z00om@hotmail.com]
    [z00om : aim]
    [77968493 : icq]

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol cheers v.nice script btw


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •