Skip to content

Instantly share code, notes, and snippets.

@julionc
Created July 13, 2012 17:25

Revisions

  1. julionc revised this gist Jul 13, 2012. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions time.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@

    <?php
    /*
    * Simple script for measuring basic measuring time
    * Simple script for basic measuring time
    *
    * See: https://groups.google.com/d/topic/phpperu/UAoqzKt2Cdc/discussion
    */
    @@ -16,4 +15,4 @@
    }

    $after = microtime(true);
    echo (($after-$before)/$i) . " seconds\n";
    echo (($after-$before)/$i) . " seconds\n";
  2. julionc created this gist Jul 13, 2012.
    19 changes: 19 additions & 0 deletions time.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@

    <?php
    /*
    * Simple script for measuring basic measuring time
    *
    * See: https://groups.google.com/d/topic/phpperu/UAoqzKt2Cdc/discussion
    */

    $before = microtime(true);

    for ($i=0 ; $i < 1000000; $i++) {
    //$result = (int)(((0.1) + (0.7)) * 10); //result: 7, should be 8
    //$result = (int) (bcmul(bcadd('0.1','0.7',1),'10')); //result: 8
    //$result = round((((0.1) + (0.7)) * 10), 0, PHP_ROUND_HALF_UP);
    $result = round((bcadd('0.1', '0.7') * 10), 0, PHP_ROUND_HALF_UP);
    }

    $after = microtime(true);
    echo (($after-$before)/$i) . " seconds\n";