Reply to Re: [PHP] intval() vs. (int)

Your name:

Reply:


Posted by Philip Hallstrom on 09/02/05 19:00

> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация