Skip to content

Instantly share code, notes, and snippets.

@julionc
Created July 13, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julionc/3106119 to your computer and use it in GitHub Desktop.
Save julionc/3106119 to your computer and use it in GitHub Desktop.
Simple script for basic measuring time - PHP
<?php
/*
* Simple script for 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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment