Posted by Chung Leong on 06/13/06 14:28
Erwin Moller wrote:
> I think you could do a general faster job by trying to match a substring to
> the filename in a certain directory, and do it once, not 10 times.
> That is sometimes refered to as 'globbing'.
> I know this from Perl, but I just saw it exists in PHP under the name....
> glob. What a surpise. ;-)
Somehow I doubt you can do a better job than the OS. Typically a binary
search is used for directory look-up. Finding one file amidst a
thousand wouldn't take more than 10 string comparisons. So for ten
look-ups the OS would do no more than 100 comparisons. Unless you write
a b-search routine in PHP yourself, you'll certainly do worse. A search
with in_array() or array_search() would require on average 500
comparisons per look-up. With a hash-table it's better, but then the
construction of it would require generating a 1000 hash keys. And if
you're on Windows you have case-sensitivity to consider...
[Back to original message]
|