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

Reply via email to