Re: intval() vs. (int)

From: Date: Fri, 02 Sep 2005 16:00:33 +0000
Subject: Re: intval() vs. (int)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-221760@lists.php.net to get a copy of this message
On checking form fields that they are of type int, what is best to use: intval() or type casting (int)? In terms of speed, would (int) not be better, because we save a function call (especially on very large sql statements)?
Time it. On an 800mhz box doing absolutely nothing else (it's just sitting there, honest :) a script which reads 100,000 16byte strings from a testfile (composed of a bunch of tar balls put together just to get something random) and then doing this: - loop through array doing $x = $array[$i] just to read it all in once. - loop through array doing $x = intval($array[$i]) - loop through array doing $x = (int) $array[$i] yields this (in seconds). nothing = 0.3619658946991 intval = 0.60399794578552 (int) = 0.48065304756165 So, for 100,000 random 16 byte strings you're saving 0.12 seconds or 0.0000012 per iteration... So, it probably doesn't really matter :) -philip

« previous php.general (#221760) next »