note 109292 deleted from function.is-int by danbrown
| From: | danbrown@php.net | Date: | Mon, 16 Jul 2012 15:52:32 +0000 |
| Subject: | note 109292 deleted from function.is-int by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189236@lists.php.net to get a copy of this message | ||
Note Submitter: 2 dot 71828183E0 at gmail dot com
----
I ran a benchmark for testing "is_int()"-like:
$v=array("q1","q2","1","2",1,2);
$s=microtime(true);
for($i=0;$i<10000000;$i++){
$x=$v[$i%count($v)];
/** compare **/
}
echo "total: ",microtime(true)-$s, "ms", PHP_EOL;
If you'll never have testing zero-values, you can this fastest method:
$x=(int)$x;
isset($v);
total: 6.97873ms
But I depricate it!
Otherwise, you should use this trick:
(int)$x==$x;
total: 7.27195ms
(not $x==(int)$x)
Then, I obtained:
is_int($x);
total: 7.61134ms
is_numeric($x);
total: 7.79037ms