[Haskell-beginners] Profiling haskell code

Brent Yorgey byorgey at seas.upenn.edu
Mon Nov 17 09:07:57 EST 2008


On Mon, Nov 17, 2008 at 09:35:26AM +0530, Sayali Kulkarni wrote:
> Hello Brent,
> 
> I just have written a quick sort program.
> There is nothing more in the code than that I have shown. 
> 
> What is it about the main function?
> What do I need to do in the main function? 
> 
> I do not get any errors.
> And I get the expected output. The only thing that I am stuck at is that
> I do not get the ".prof" file which will give me the profile details of
> the code.
> 
> Also it would be great if you could through a light on whether there is
> any other method to profile a code in Haskell? 
> 
> Regards,
> Sayali.

Hi Sayali,

Just writing a quicksort function by itself is fine if you want to
test it interactively in ghci.  But if you want to profile it you will
have to make an executable, which means you will need a 'main'
function which says what to do when the program is run.  Your main
function might look something like this:

main = do print "Sorting..."
          print (length (quicksort (reverse [1..1000000])))
          print "Done!"

Of course, sorting a list in reverse order might not be a very
representative task; you might also want to look into the
System.Random module to generate a list of a million random elements
and sort that.

-Brent

> 
> -----Original Message-----
> From: beginners-bounces at haskell.org
> [mailto:beginners-bounces at haskell.org] On Behalf Of Brent Yorgey
> Sent: Saturday, November 15, 2008 2:24 AM
> To: beginners at haskell.org
> Subject: Re: [Haskell-beginners] Profiling haskell code
> 
> > 
> > quicksort [ ] = [ ]
> > 
> > quicksort (x : xs) = quicksort larger ++ [x ] ++ quicksort smaller
> > 
> >  
> > where
> > 
> >  
> > smaller = [a | a <- xs, a <= x ]
> > 
> >  
> > larger = [b | b <- xs, b > x ]
> > 
> >  
> > 
> >  
> > 
> > When I compile the code with the following command : 
> > 
> >  
> > 
> > $ ghc --make Project.hs -prof -auto-all
> >  
> > Then I tested it with the following command :
> >  
> > $ Project +RTS -p
> >  
> > It generates the .hi and the .o file but I cannot get the .prof file. 
> >  
> > Please let me know if any of the steps is missing or where could I
> check
> > my profiling info. 
> > 
> 
> Hi Sayali,
> 
> Is the code shown above *everything* in your Project.hs file?  You
> will also need a main function for it to actually do anything.  If
> there is more to your Project.hs file that you have not shown, could
> you send the complete version?
> 
> Do you get any errors?  Does Project produce the output that you expect?
> 
> -Brent
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
> 


More information about the Beginners mailing list