Re: intval() vs. (int)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(int) seems to be faster, but not by an awful lot. Personally however
if its a case of typing five characters (int) and saving a little exec
time, or typing 8 and losing a little, then I'd perfer to go with the
five an save the exec time.

I think I remember hearing about some other consequence with using the
intval function call, but can't remember what it was.

On 9/2/05, Philip Hallstrom <php@xxxxxxxxxxxxxxx> wrote:
> > 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
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux