Skip to content

Instantly share code, notes, and snippets.

@julionc julionc/time.php
Created Jul 13, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.