1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php
define('N_BOUCLES', 1000);
define('MODULO', 32);
function getmicrotime()
{
list($usec, $sec) = explode(' ',microtime());
return ((float)$usec + (float)$sec);
}
////////// TEST 1 classic pow
$start = getmicrotime();
$test=0;
for($i=0;$i<N_BOUCLES;$i++) {
$test += pow(2,i%MODULO);
}
echo $test.' '.(getmicrotime()-$start).'<br/>';
////////// TEST 2 BC pow
$start = getmicrotime();
$test=0;
for($i=0;$i<N_BOUCLES;$i++) {
$test = bcadd($test, bcpow('2',strval($i%MODULO),0),0);
}
echo $test.' '.(getmicrotime()-$start).'<br/>';
////////// TEST 3 BC multiply
$start = getmicrotime();
$test=0;
for($i=0;$i<N_BOUCLES;$i++) {
if($i%MODULO==0) $bit = '1';
$test = bcadd($test, $bit,0);
$bit = bcmul($bit,'2',0);
}
echo $test.' '.(getmicrotime()-$start).'<br/>';
////////// TEST 4 GMP pow
$start = getmicrotime();
$test=gmp_init(0);
for($i=0;$i<N_BOUCLES;$i++) {
$test = gmp_add($test, gmp_pow('2',$i%MODULO));
}
echo $test.' '.(getmicrotime()-$start).'<br/>';
////////// TEST 5 GMP setbit
$start = getmicrotime();
$test=gmp_init(0);
for($i=0;$i<N_BOUCLES;$i++) {
$test = gmp_setbit($test, $i%MODULO);
}
echo gmp_strval($test).' '.(getmicrotime()-$start).'<br/>';
////////// TEST 6 Bit to bit Classic
$start = getmicrotime();
$test=0;
for($i=0;$i<N_BOUCLES;$i++) {
if($i%MODULO==0) $bit = '1';
$test += $bit;
$bit = $bit<<1;
}
echo $test.' '.(getmicrotime()-$start).'<br/>';
?> |
Partager