[Haskell-beginners] code critique

Gary Klindt gary.klindt at uni-konstanz.de
Thu Jul 28 00:59:50 CEST 2011


I repeated the profiling:

print $ sumCheck 500 [1..1000] [1..1000]
sumCheck1: 58,648
sumCheck2: 58,484
sumCheck3: 70,016
print $ sumCheck 5000 [1..10000] [1..10000]
sumCheck1: 238,668
sumCheck2: 238,504
sumCheck3: 358,016
(unit: byte)

This time I used the same compiler flags as Aditya (all but -rtsopts, I 
got:ghc: unrecognised flags: -rtsopts ). I'm using  GHC version 6.12.1.

Ok, in this numerical example, the scaling of sumCheck3 is not worse 
than the other's. In my first run I used quasi random numbers (fingers 
on my keyboard). Maybe you got puzzled with your '.prof' files? They 
seem identical (there always exists a function sum)


On 07/27/2011 07:34 AM, aditya siram wrote:
> I just profiled all three and have not found them to be different.
> Maybe I'm reading my profiler output wrong so I've pasted it below.
> The compilation command I used was:
> ghc -fforce-recomp -XBangPatterns -prof -rtsopts -auto-all -o
> ListCrossProductSum ListCrossProductSum.hs
>
> They were all invoked using:
> main = print $ sumCheck 5000 [1..10000] [1..10000]
>
> I am running GHC 7.0.1
>
> -deech
>
> sumcheck1:
> ==========
> 	  Wed Jul 27 00:26 2011 Time and Allocation Profiling Report  (Final)
>
> 	     ListCrossProductSum +RTS -p -RTS
>
> 	  total time  =        0.00 secs   (0 ticks @ 20 ms)
> 	  total alloc =     344,084 bytes  (excludes profiling overheads)
>
>    COST CENTRE                    MODULE               %time %alloc
>
>    sums                           Main                   0.0   40.7
>    main                           Main                   0.0   58.3
>
>
> 												 individual    inherited
>    COST CENTRE              MODULE
>           no.    entries  %time %alloc   %time %alloc
>
>    MAIN                     MAIN
>             1           0   0.0    0.0     0.0  100.0
>     CAF                     Main
>           240           2   0.0    0.2     0.0   99.2
>      main                   Main
>           246           1   0.0   58.3     0.0   99.0
>       sumCheck              Main
>           247           1   0.0    0.0     0.0   40.7
>        sums                 Main
>           248           1   0.0   40.7     0.0   40.7
>     CAF                     GHC.Show
>           236           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.FD
>           176           2   0.0    0.4     0.0    0.4
>     CAF                     System.Posix.Internals
>           175           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.Internals
>           140           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Encoding.Iconv
>           134           2   0.0    0.3     0.0    0.3
>     CAF                     GHC.Conc.Signal
>           131           1   0.0    0.1     0.0    0.1
>
> sumcheck2
> =========
>    [1 of 1] Compiling Main             ( ListCrossProductSum.hs,
> ListCrossProductSum.o )
>    True
> 	  Wed Jul 27 00:27 2011 Time and Allocation Profiling Report  (Final)
>
> 	     ListCrossProductSum +RTS -p -RTS
>
> 	  total time  =        0.00 secs   (0 ticks @ 20 ms)
> 	  total alloc =     344,084 bytes  (excludes profiling overheads)
>
>    COST CENTRE                    MODULE               %time %alloc
>
>    sums                           Main                   0.0   40.7
>    main                           Main                   0.0   58.3
>
>
> 												 individual    inherited
>    COST CENTRE              MODULE
>           no.    entries  %time %alloc   %time %alloc
>
>    MAIN                     MAIN
>             1           0   0.0    0.0     0.0  100.0
>     CAF                     Main
>           240           2   0.0    0.2     0.0   99.2
>      main                   Main
>           246           1   0.0   58.3     0.0   99.0
>       sumCheck              Main
>           247           1   0.0    0.0     0.0   40.7
>        sums                 Main
>           248           1   0.0   40.7     0.0   40.7
>     CAF                     GHC.Show
>           236           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.FD
>           176           2   0.0    0.4     0.0    0.4
>     CAF                     System.Posix.Internals
>           175           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.Internals
>           140           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Encoding.Iconv
>           134           2   0.0    0.3     0.0    0.3
>     CAF                     GHC.Conc.Signal
>           131           1   0.0    0.1     0.0    0.1
>
> sumcheck3
> =========
> 	     ListCrossProductSum +RTS -p -RTS
>
> 	  total time  =        0.00 secs   (0 ticks @ 20 ms)
> 	  total alloc =     344,084 bytes  (excludes profiling overheads)
>
>    COST CENTRE                    MODULE               %time %alloc
>
>    sums                           Main                   0.0   40.7
>    main                           Main                   0.0   58.3
>
>
> 												 individual    inherited
>    COST CENTRE              MODULE
>           no.    entries  %time %alloc   %time %alloc
>
>    MAIN                     MAIN
>             1           0   0.0    0.0     0.0  100.0
>     CAF                     Main
>           240           2   0.0    0.2     0.0   99.2
>      main                   Main
>           246           1   0.0   58.3     0.0   99.0
>       sumCheck              Main
>           247           1   0.0    0.0     0.0   40.7
>        sums                 Main
>           248           1   0.0   40.7     0.0   40.7
>     CAF                     GHC.Show
>           236           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.FD
>           176           2   0.0    0.4     0.0    0.4
>     CAF                     System.Posix.Internals
>           175           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Handle.Internals
>           140           1   0.0    0.0     0.0    0.0
>     CAF                     GHC.IO.Encoding.Iconv
>           134           2   0.0    0.3     0.0    0.3
>     CAF                     GHC.Conc.Signal
>           131           1   0.0    0.1     0.0    0.1




More information about the Beginners mailing list