<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
<div class="moz-text-flowed"
 style="font-family: -moz-fixed; font-size: 13px;" lang="x-western">Hello
again folks,
<br>
<br>
Sorry to keep troubling you - I'm very appreciative of the help you've
given so far. I've got one more for you that has got me totally
stumped. I'm writing a program which deals with largish-files, the one
I am using as a test case is not stupidly large at about 200mb. After
three evenings, I have finally gotten rid of all the stack overflows,
but I am unfortunately left with something that is rather unfeasably
slow. I was hoping someone with some keener skills than I could take a
look, I've tried to distill it to the simplest case.
<br>
<br>
This program just reads in a file, interpreting each value as a double,
and does a sort of running average on them. The actual function doesn't
matter too much, I think it is the reading it in that is the problem.
Here's the code:
<br>
<br>
import Control.Exception
<br>
import qualified Data.ByteString.Lazy as BL
<br>
import Data.Binary.Get
<br>
import System.IO
<br>
import Data.Binary.IEEE754
<br>
<br>
myGetter acc = do
<br>
&nbsp;&nbsp;&nbsp; e &lt;- isEmpty
<br>
&nbsp;&nbsp;&nbsp; if e == True
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return acc
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else do
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t &lt;- getFloat64le
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myGetter $! ((t+acc)/2)
<br>
<br>
myReader file = do
<br>
&nbsp;&nbsp;&nbsp; h &lt;- openBinaryFile file ReadMode
<br>
&nbsp;&nbsp;&nbsp; bs &lt;- BL.hGetContents h
<br>
&nbsp;&nbsp;&nbsp; return $ runGet (myGetter 0)&nbsp; bs
<br>
<br>
main = do
<br>
&nbsp;&nbsp;&nbsp; d &lt;- myReader "data.bin"
<br>
&nbsp;&nbsp;&nbsp; evaluate d
<br>
<br>
This takes about three minutes to run on my (fairly modern) laptop..
The equivilant C program takes about 5 seconds.
<br>
<br>
I'm sure I am doing something daft, but I can't for the life of me see
what. Any hints about how to get the profiler to show me useful stuff
would be much appreciated!
<br>
<br>
All the best,
<br>
<br>
Philip
<br>
<br>
PS: If, instead of computing a single value I try and build a list of
the values, the program ends up using over 2gb of memory to read a
200mb file.. any ideas on that one?
<br>
<br>
</div>
</body>
</html>