0

So I'm a bit confused about how the DirectoryIterator works.

Let's say I have a directory with 100000 files. Using the readdir() function I could easily walk through the entire file list without any performance hits, because the function gets me one file at the time.

Does the DirectoryIterator work in the same way, or does it read the entire directory when you construct the object, and stores it into some internal array (like scandir() for example) ?

Normally it shouldn't do that because it's an iterator and has next() method etc, but it seems pretty slow compared to readdir so I thought I should ask to make sure.

3
  • What about little selfmade test?
    – sectus
    Nov 14, 2013 at 3:13
  • I did that and the iterator is slower, but the difference is small because i don't have that many files yet :)
    – thelolcat
    Nov 14, 2013 at 3:14
  • You want to know about memory, use memory_get_usage.
    – sectus
    Nov 14, 2013 at 3:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.