[Haskell-cafe] Comments and suggestions on code
Jonathan Cast
jonathanccast at fastmail.fm
Fri Jan 11 22:14:41 EST 2008
On 11 Jan 2008, at 2:20 PM, Andre Nathan wrote:
> 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
These are all known and expected. As I said, you can expect lazy
versions to normally be slower than explicit loops. The question is
whether 50% more time and 300% more memory has a higher cost in your
case than the extra complexity and reduced modularity of the lazy code.
jcc
More information about the Haskell-Cafe
mailing list