Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: optimisation of code (PICCA Frederic-Emmanuel) 2. Re: optimisation of code (PICCA Frederic-Emmanuel) ---------------------------------------------------------------------- Message: 1 Date: Mon, 1 Oct 2018 16:59:39 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] optimisation of code Message-ID: <a2a20ec3b8560d408356cac2fc148e53015b330...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" > Hi, > Current code re-checks file existence always in same order, so worst case is > - N files and only last of them does not exists. > In that case this code will re-check (N-1) files during each consecutive > retry. > This can be optimized by moving already existing files to the end of file > list(or dropping them from list completely, if files are only > > added but > never removed). > For this you could re-write `allFilesThere` something like: > allFilesThere fs = liftIO $ do > existing, non_existing <- partitionM (doesFileExist . fromAbsFile) fs < return (non_existing++ existing, null non_existing) > Then allFilesThere could start next iteration by checking previously > non-existing files and probably failing much faster. thanks a lot, files are never removed, so I can forget already checked files :) ------------------------------ Message: 2 Date: Mon, 1 Oct 2018 17:01:48 +0000 From: PICCA Frederic-Emmanuel <frederic-emmanuel.pi...@synchrotron-soleil.fr> To: "The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell" <beginners@haskell.org> Subject: Re: [Haskell-beginners] optimisation of code Message-ID: <a2a20ec3b8560d408356cac2fc148e53015b330...@sun-dag3.synchrotron-soleil.fr> Content-Type: text/plain; charset="us-ascii" > My first instinct is to just use anyM instead of allM > allFilesThere :: MonadIO m => [Path Abs File] -> m Bool > allFilesThere fs = liftIO $ anyM (not . doesFileExist . fromAbsFile) fs > However you'll now have the opposite problem. It will take a lot of > resources when all the files are there. But maybe that is okay for your use > case? I need to reduce the worload when a file is missing. I like a lot the partition idea. Cheers Frederic ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 124, Issue 1 *****************************************