<?php class X { protected $val = []; function notempty() { return ! empty( $this->val ); } function booltest() { return (bool) $this->val; } } $its = 1e3; $x = new X; $t = hrtime(true); for ($i=0;$i++<$its;) $x->notempty(); echo (hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ($i=0;$i++<$its;) $x->booltest(); echo (hrtime(true)-$t)/1e9,"s\n"; echo "\n=== Warmed up ===\n\n"; $its = 1e5; $t = hrtime(true); for ($i=0;$i++<$its;) $x->notempty(); echo 'notempty: ', $a=(hrtime(true)-$t)/1e9,"s\n"; $t = hrtime(true); for ($i=0;$i++<$its;) $x->booltest(); echo 'bool : ', $b=(hrtime(true)-$t)/1e9,"s\n"; echo 'bool is ', number_format((($a-$b)/$a) * 100, 2 ), "% faster than notempty chain\n";
You have javascript disabled. You will not be able to edit any code.