[Haskell-cafe] Comments and suggestions on code

Andre Nathan andre at digirati.com.br
Fri Jan 11 17:20:40 EST 2008


On Fri, 2008-01-11 at 13:27 -0200, Andre Nathan wrote:
> I was wondering if laziness would make it run as if it was a single O(n)
> operation (get one directory entry "on demand", pass it to filter and
> then to insertInTree), because only one entry is used at a time, so that
> only the "current" entry needs to be evaluated.

I did some experiments. This for 1000 reads of the entries of a
directory with 10000 entries, checking if they match ^[0-9]+$ and
printing those which do (half of them).

getDirectoryEntries, filter, mapM_:
  65.52s user 6.01s system 87% cpu 1:22.21 total

openDirStream, readDirStream:
  39.68s user 5.69s system 95% cpu 47.746 total

getDirectoryContents, mapM_:
  63.40s user 5.96s system 95% cpu 1:12.70 total

Both versions which use getDirectoryContents also use much more memory
than the one which uses readDirStream (about 8M vs about 2M). Maybe I'm
not exploting getDirectoryContents' laziness correctly? I expected the
second and third versions to run in about the same time.

Andre



More information about the Haskell-Cafe mailing list