Profiling haskell code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Profiling haskell code

Sayali Kulkarni
Hello,

 

I am new to Haskell. I have written a small quicksort function in
Haskell. I want to profile it for time.

 

I have GHC 6.10.1 version and I have also installed the extra-libs that
it has on the Haskell home page.

 

I followed the following steps for installing the extra-libs:

 

$ cd /to/the/library/source
$ runghc Setup.hs configure --enable-library-profiling
$ runghc Setup.hs build
$ runghc Setup.hs install

 

Following is the quicksort code that I'm using:

 

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.

 

 

Regards,

Sayali.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081113/4351dc75/attachment-0001.htm
Reply | Threaded
Open this post in threaded view
|

Profiling haskell code

Brent Yorgey-2
>
> 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
Reply | Threaded
Open this post in threaded view
|

Profiling haskell code

Sayali Kulkarni
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.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Brent Yorgey
Sent: Saturday, November 15, 2008 2:24 AM
To: [hidden email]
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
[hidden email]
http://www.haskell.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Profiling haskell code

Brent Yorgey-2
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: [hidden email]
> [mailto:[hidden email]] On Behalf Of Brent Yorgey
> Sent: Saturday, November 15, 2008 2:24 AM
> To: [hidden email]
> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/beginners
>