- var_dump: documentation ( source)
- microtime: documentation ( source)
<?php
$iterations = 1000000;
$strOne = '1';
$strEmpty = '';
$times = ['oneOpEq' => 0,
'oneSlen' => 0,
'empOpEq' => 0,
'empSlen' => 0];
$x = $iterations;
$start = microtime(true);
while ($x--) { $y = ($strOne === '1'); }
$times['oneOpEq'] = microtime(true) - $start;
$x = $iterations;
$start = microtime(true);
while ($x--) { $y = (strlen($strOne) == 0); }
$times['oneSlen'] = microtime(true) - $start;
$x = $iterations;
$start = microtime(true);
while ($x--) { $y = ($strEmpty === ''); }
$times['empOpEq'] = microtime(true) - $start;
$x = $iterations;
$start = microtime(true);
while ($x--) { $y = (strlen($strEmpty) == 0); }
$times['empSlen'] = microtime(true) - $start;
var_dump($times);