SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard xyuri's Avatar
    Join Date
    Jul 2002
    Location
    Brisbane
    Posts
    1,487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help finding problem in code using time microtime()

    Sorry if i am too straightforeward with this problem, but i have the following and its displaying times at the end with numbers suck as "10" and "20"

    PHP Code:
    <html>
    <style>
        body {font-family: verdana; font-size: 10px}
    </style>
    <body>

    <?PHP
    error_reporting
    (E_ALL);

    Function 
    now_time ()
        {list (
    $msec,$sec) = explode(" ",microtime());
        
    $msec_now = ((float)$sec + (float)$msec);
        return 
    $msec_now;}

    // Variables
    $db_server "LOCALHOST";
    $db_database 'xyuri_benchmark_test';
    $db_user 'root';
    $db_pass '';

    $link1 mysql_connect($db_server$db_user$db_pass);
    mysql_query("Create database $db_database");
    mysql_select_db("$db_database");
    ECHO 
    "<li><small>Database (<i>$db_database</i>) created sucessfully.</small><br/><br/>";

    $start_1 now_time ();
    /* START Table 1 */
    mysql_query("Create Table table_1(id int auto_increment primary key)");
    mysql_query("Insert into table_1 values ('0')");
    ECHO 
    '<li><small>First table created sucessfully.</small><br/>';

    $x = (int)0;
    WHILE (
    $x < (int)200
        {
        
    mysql_query("UPDATE table_1 SET id = $x");
        
    $x++;
        } unset(
    $x);
    /* FINISH Table 1 */
    $finish_1 now_time ();

    $start_2 now_time ();
    /* START Table 2 */
    mysql_query("Create Table table_2(id int auto_increment primary key)");
    mysql_query("Insert into table_2 values ('0')");
    ECHO 
    '<li><small>Second table created sucessfully.</small><br/>';

    $x = (int)0;
    WHILE (
    $x < (int)200
        {
        
    mysql_query("UPDATE table_1 SET id = (id + 1)");
        
    $x++;
        } unset(
    $x);
    /* FINISH Table 2 */
    $finish_2 now_time ();

    mysql_query("drop database $db_database");
    ECHO 
    "<br/><li><small>Database (<i>$db_database</i>) dropped sucessfully.</small><br/><br/>";
    ?>

    <b>Results:</b><br/>

    <?PHP
    $time_1 
    = ((float)$finish_1 - (float)$start_1);
    $time_2 = ((float)$finish_2 - (float)$start_2);

    ECHO 
    '1' round($time_1,2) . '<br/>';
    ECHO 
    '2' round($time_2,2) . '<br/>';
    ?>

    </body>
    </html>
    but really the code takes like 3 seconds to generate

    any visual problems ?

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What happens if you echo $time_1 and $time_2 without the round( ) function?
    Ian Anderson
    www.siteguru.co.uk


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
  •