inits

Tim Toorop timtoorop at quicknet.nl
Mon Apr 10 19:22:08 EDT 2006


Chris Kuklewicz wrote:
> Tim Toorop wrote:
>   
>> Chris Kuklewicz wrote:
>>     
>>> Ross Paterson wrote:
>>>  
>>>       
>>>> On Mon, Apr 10, 2006 at 03:54:09PM +0100, Chris Kuklewicz wrote:
>>>>    
>>>>         
>>>>> If the goal is speed, then this definition is running over 10%
>>>>> faster with ghc
>>>>> -O2 on my powerbook for (sum $ map length $ inits [1..10000])
>>>>>
>>>>> inits' = helper id
>>>>>     where helper f [] = (f []):[]
>>>>>           helper f (x:xs) = (f []):helper (f.(x:)) xs
>>>>>       
>>>>>           
>>>> I rather like
>>>>
>>>>     inits = map ($ []) . scanl (.) id . map (:)
>>>>
>>>>     
>>>>         
>>> That takes 3 times longer than the helper function definition. 
>>> Barring fusion,
>>> it is creating an extra list.  The "scanl" makes a list, the "map"
>>> makes a list
>>> and the "(f [])" makes a list.
>>>
>>> The helper function makes a list with "(f[])" and with "(...):helper...".
>>>
>>>  
>>>       
>>>> but this is also competitive:
>>>>
>>>>     inits = map reverse . scanl (flip (:)) []
>>>>
>>>>     
>>>>         
>>> I would never try "reverse" when looking for performance, but that
>>> runs at the
>>> same speed as the helper and allocates the same amount of space.
>>>
>>>   
>>>       
>> I think we need to create a test case or something, before we say one
>> function is better then the other.
>>     
>
> Defining best is tricky.  That is why I told everyone my usage was (sum $ map
> length $ inits [1..10000]).
>
>   
>> Just like with the helper function.  The originally proposed function is
>> sometimes a tad faster then the helper function.
>> And sometimes very much slower.
>>     
>
> Could you tell me what your usage is?
>
>   
>> So we need to know what is important in the use of inits.
>>     
>
> I am going out on a limb here and say : The usage metric must consume all of the
> output of inits.
>
> If someone wants
> (1) less than all the output of inits, and
> (2) wants the highest performance
> then they should consider writing a more specialized function to use instead of
> inits.
>
> If someone wants
> (1) all of the output of inits
> (2) wants the highest performance
> then they should not have to replace the inits in Data.List
>
>   
>> And then see which one is faster with probably -O2 added.
>>     
>
> Testing performance without -O2 is interesting, but anyone who cares whether
> Data.List.inits gets replaced will be using optimizations.
>
>   
>> Because the functions seem act very differently in the ghci (VERY!)
>>     
>
> Of course.
>   

Ok, I did some tests.
And I think the inits with the helper is generally the fastest with 
compiling with -O2 
(I also don't think the ghci matters much, since nobody is probably 
using haskell programs from the ghci)
For those of you who do want to use it in the ghci... The inits with the 
helper function is by far the slowest in the ghci.
inits3 is the best for use in the ghci  (and fits easily in a let 
inits... in inits )

inits1 xs = [] : (zipWith take [1..] $ map (const xs) xs)

inits2 = helper id
    where helper f [] = (f []):[]
          helper f (x:xs) = (f []):helper (f.(x:)) xs

inits3 = map reverse . scanl (flip (:)) []


examples:
main = print (sum $ map sum $ inits1 [1..20000])

inits1:
real    0m17.710s
user    0m17.457s
sys     0m0.136s

inits2:
real    0m15.489s
user    0m15.265s
sys     0m0.128s

inits3:
real    0m12.251s
user    0m12.080s
sys     0m0.107s

main = print (sum $ inits1 [1..] !! 5000000)
inits1:
real    0m4.909s
user    0m4.393s
sys     0m0.417s

inits2:
real    0m5.992s
user    0m5.477s
sys     0m0.435s

inits3:
real    0m8.277s
user    0m7.780s
sys     0m0.401s


So you see. There is not 'a' fastest inits here.

--
Tim Toorop


-------------- next part --------------
main = print (sum $ map sum $ inits1 [1..20000])

inits1:
real    0m17.710s
user    0m17.457s
sys     0m0.136s

6,405,773,340 bytes allocated in the heap
2,124,612,484 bytes copied during GC
    426,528 bytes maximum residency (1982 sample(s))

      24433 collections in generation 0 (  5.08s)
       1982 collections in generation 1 (  2.66s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    9.77s  (  9.75s elapsed)
  GC    time    7.74s  (  8.11s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time   17.51s  ( 17.86s elapsed)

  %GC time      44.2%  (45.4% elapsed)

  Alloc rate    655,657,455 bytes per MUT second

  Productivity  55.8% of total user, 54.7% of total elapsed

inits2:

real    0m15.489s
user    0m15.265s
sys     0m0.128s

4,006,422,940 bytes allocated in the heap
2,136,413,112 bytes copied during GC
    655,988 bytes maximum residency (1055 sample(s))

      15280 collections in generation 0 (  4.86s)
       1055 collections in generation 1 (  1.81s)

          3 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    8.54s  (  8.52s elapsed)
  GC    time    6.67s  (  6.95s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time   15.21s  ( 15.47s elapsed)

  %GC time      43.9%  (44.9% elapsed)

  Alloc rate    469,136,175 bytes per MUT second

  Productivity  56.1% of total user, 55.2% of total elapsed



inits3:
./a.out +RTS -sstderr
1333533340000
4,006,503,460 bytes allocated in the heap
1,247,253,272 bytes copied during GC
    660,184 bytes maximum residency (76 sample(s))

      15280 collections in generation 0 (  3.26s)
         76 collections in generation 1 (  0.16s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    8.65s  (  8.29s elapsed)
  GC    time    3.42s  (  3.96s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time   12.07s  ( 12.25s elapsed)

  %GC time      28.3%  (32.3% elapsed)

  Alloc rate    463,179,590 bytes per MUT second

  Productivity  71.7% of total user, 70.6% of total elapsed


real    0m12.251s
user    0m12.080s
sys     0m0.107s

-------------- next part --------------
main = print (length $ map sum $ inits [1..10000000])

inits1:
./a.out +RTS -sstderr
10000001
1,927,409,632 bytes allocated in the heap
484,969,800 bytes copied during GC
142,899,112 bytes maximum residency (9 sample(s))

       7352 collections in generation 0 (  1.04s)
          9 collections in generation 1 (  1.55s)

        275 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    2.42s  (  2.51s elapsed)
  GC    time    2.59s  (  3.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.01s  (  5.51s elapsed)

  %GC time      51.7%  (54.4% elapsed)

  Alloc rate    796,450,261 bytes per MUT second

  Productivity  48.3% of total user, 43.9% of total elapsed


real    0m5.567s
user    0m5.013s
sys     0m0.395s


inits2:
./a.out +RTS -sstderr
10000001
1,241,220,400 bytes allocated in the heap
701,736,288 bytes copied during GC
151,593,700 bytes maximum residency (9 sample(s))

       4734 collections in generation 0 (  1.63s)
          9 collections in generation 1 (  1.68s)

        292 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.60s  (  1.53s elapsed)
  GC    time    3.31s  (  3.82s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    4.91s  (  5.35s elapsed)

  %GC time      67.4%  (71.4% elapsed)

  Alloc rate    775,762,750 bytes per MUT second

  Productivity  32.6% of total user, 29.9% of total elapsed


real    0m5.414s
user    0m4.910s
sys     0m0.387s

inits3:
./a.out +RTS -sstderr
10000001
1,161,924,400 bytes allocated in the heap
785,531,992 bytes copied during GC
153,038,768 bytes maximum residency (9 sample(s))

       4432 collections in generation 0 (  2.01s)
          9 collections in generation 1 (  1.74s)

        295 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.59s  (  1.62s elapsed)
  GC    time    3.75s  (  4.21s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.34s  (  5.83s elapsed)

  %GC time      70.2%  (72.2% elapsed)

  Alloc rate    730,770,062 bytes per MUT second

  Productivity  29.8% of total user, 27.3% of total elapsed


real    0m5.884s
user    0m5.341s
sys     0m0.445s

-------------- next part --------------
main = print (length $ inits1 [1..10000000])

inits1:
./a.out +RTS -sstderr
10000001
1,563,333,496 bytes allocated in the heap
491,073,020 bytes copied during GC
146,087,820 bytes maximum residency (9 sample(s))

       5963 collections in generation 0 (  0.96s)
          9 collections in generation 1 (  1.63s)

        282 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    2.13s  (  2.23s elapsed)
  GC    time    2.59s  (  2.89s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    4.72s  (  5.12s elapsed)

  %GC time      54.9%  (56.4% elapsed)

  Alloc rate    733,959,387 bytes per MUT second

  Productivity  45.1% of total user, 41.6% of total elapsed


real    0m5.183s
user    0m4.728s
sys     0m0.388s


inits2:
./a.out +RTS -sstderr
10000001
880,860,504 bytes allocated in the heap
718,379,884 bytes copied during GC
160,190,556 bytes maximum residency (9 sample(s))

       3360 collections in generation 0 (  1.33s)
          9 collections in generation 1 (  1.78s)

        309 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.42s  (  1.38s elapsed)
  GC    time    3.11s  (  3.76s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    4.53s  (  5.14s elapsed)

  %GC time      68.7%  (73.2% elapsed)

  Alloc rate    620,324,298 bytes per MUT second

  Productivity  31.3% of total user, 27.6% of total elapsed


real    0m5.198s
user    0m4.537s
sys     0m0.470s


inits3:

./a.out +RTS -sstderr
10000001
1,161,924,400 bytes allocated in the heap
785,531,992 bytes copied during GC
153,038,768 bytes maximum residency (9 sample(s))

       4432 collections in generation 0 (  2.05s)
          9 collections in generation 1 (  1.71s)

        295 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.41s  (  1.67s elapsed)
  GC    time    3.76s  (  4.01s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.17s  (  5.68s elapsed)

  %GC time      72.7%  (70.6% elapsed)

  Alloc rate    824,059,858 bytes per MUT second

  Productivity  27.3% of total user, 24.8% of total elapsed


real    0m5.738s
user    0m5.179s
sys     0m0.417s
-------------- next part --------------
main = print (or $ concat $ inits1 $  ((replicate 20000 False) ++[True] ++ []  )  )

inits1:
./a.out +RTS -sstderr
True
4,822,652,444 bytes allocated in the heap
1,427,002,776 bytes copied during GC
    266,116 bytes maximum residency (1325 sample(s))

      18397 collections in generation 0 (  5.19s)
       1325 collections in generation 1 (  0.86s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    5.57s  (  6.03s elapsed)
  GC    time    6.05s  (  5.87s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time   11.62s  ( 11.90s elapsed)

  %GC time      52.1%  (49.3% elapsed)

  Alloc rate    865,826,291 bytes per MUT second

  Productivity  47.9% of total user, 46.8% of total elapsed


real    0m11.893s
user    0m11.622s
sys     0m0.176s


inits2:
./a.out +RTS -sstderr
True
2,404,621,440 bytes allocated in the heap
731,744,312 bytes copied during GC
     28,236 bytes maximum residency (1 sample(s))

       9172 collections in generation 0 (  1.88s)
          1 collections in generation 1 (  0.00s)

          1 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    3.31s  (  3.09s elapsed)
  GC    time    1.88s  (  2.28s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.19s  (  5.37s elapsed)

  %GC time      36.2%  (42.5% elapsed)

  Alloc rate    726,471,734 bytes per MUT second

  Productivity  63.8% of total user, 61.6% of total elapsed


real    0m5.374s
user    0m5.199s
sys     0m0.135s

inits3:
./a.out +RTS -sstderr
True
2,404,856,640 bytes allocated in the heap
729,353,700 bytes copied during GC
     30,124 bytes maximum residency (1 sample(s))

       9173 collections in generation 0 (  2.11s)
          1 collections in generation 1 (  0.00s)

          1 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    3.07s  (  3.36s elapsed)
  GC    time    2.11s  (  1.96s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.18s  (  5.32s elapsed)

  %GC time      40.7%  (36.8% elapsed)

  Alloc rate    783,340,925 bytes per MUT second

  Productivity  59.3% of total user, 57.7% of total elapsed


real    0m5.319s
user    0m5.183s
sys     0m0.059s
-------------- next part --------------
main = print (sum $ inits1 [1..] !! 5000000)

inits1:

./a.out +RTS -sstderr
12500002500000
1,319,160,468 bytes allocated in the heap
408,728,680 bytes copied during GC
 91,254,564 bytes maximum residency (9 sample(s))

       4276 collections in generation 0 (  1.02s)
          9 collections in generation 1 (  1.46s)

        227 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.91s  (  1.98s elapsed)
  GC    time    2.48s  (  2.89s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    4.39s  (  4.87s elapsed)

  %GC time      56.5%  (59.3% elapsed)

  Alloc rate    690,659,930 bytes per MUT second

  Productivity  43.5% of total user, 39.2% of total elapsed


real    0m4.909s
user    0m4.393s
sys     0m0.417s

inits2:
./a.out +RTS -sstderr
12500002500000
916,901,092 bytes allocated in the heap
681,934,332 bytes copied during GC
120,143,084 bytes maximum residency (9 sample(s))

       2742 collections in generation 0 (  1.64s)
          9 collections in generation 1 (  2.00s)

        275 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    1.83s  (  1.78s elapsed)
  GC    time    3.64s  (  4.16s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.47s  (  5.94s elapsed)

  %GC time      66.5%  (70.0% elapsed)

  Alloc rate    501,038,848 bytes per MUT second

  Productivity  33.5% of total user, 30.8% of total elapsed


real    0m5.992s
user    0m5.477s
sys     0m0.435s

inits3:
./a.out +RTS -sstderr
12500002500000
1,117,490,752 bytes allocated in the heap
801,070,420 bytes copied during GC
136,574,424 bytes maximum residency (10 sample(s))

       3507 collections in generation 0 (  2.59s)
         10 collections in generation 1 (  3.34s)

        288 Mb total memory in use

  INIT  time    0.00s  (  0.01s elapsed)
  MUT   time    1.84s  (  1.89s elapsed)
  GC    time    5.93s  (  6.32s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    7.77s  (  8.22s elapsed)

  %GC time      76.3%  (76.9% elapsed)

  Alloc rate    607,331,930 bytes per MUT second

  Productivity  23.7% of total user, 22.4% of total elapsed


real    0m8.277s
user    0m7.780s
sys     0m0.401s
-------------- next part --------------
main = print ( sum $ map sum $ take 7000 $ drop 10000 $ inits1 [1..])

inits1:
./a.out +RTS -sstderr
652166665500
3,027,739,192 bytes allocated in the heap
1,198,514,144 bytes copied during GC
    366,448 bytes maximum residency (1116 sample(s))

      11548 collections in generation 0 (  3.11s)
       1116 collections in generation 1 (  1.39s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.62s  (  4.62s elapsed)
  GC    time    4.50s  (  4.72s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    9.12s  (  9.34s elapsed)

  %GC time      49.3%  (50.5% elapsed)

  Alloc rate    655,354,803 bytes per MUT second

  Productivity  50.7% of total user, 49.5% of total elapsed


real    0m9.342s
user    0m9.128s
sys     0m0.143s


inits2:

./a.out +RTS -sstderr
652166665500
1,893,647,932 bytes allocated in the heap
981,247,684 bytes copied during GC
    566,448 bytes maximum residency (444 sample(s))

       7222 collections in generation 0 (  2.06s)
        444 collections in generation 1 (  0.72s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.01s elapsed)
  MUT   time    4.35s  (  4.35s elapsed)
  GC    time    2.78s  (  2.95s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    7.13s  (  7.31s elapsed)

  %GC time      39.0%  (40.4% elapsed)

  Alloc rate    435,321,363 bytes per MUT second

  Productivity  61.0% of total user, 59.5% of total elapsed


real    0m7.309s
user    0m7.131s
sys     0m0.133s

inits3:

./a.out +RTS -sstderr
652166665500
1,894,330,720 bytes allocated in the heap
979,096,380 bytes copied during GC
    564,824 bytes maximum residency (443 sample(s))

       7225 collections in generation 0 (  1.94s)
        443 collections in generation 1 (  0.93s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.24s  (  4.29s elapsed)
  GC    time    2.87s  (  2.95s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    7.11s  (  7.24s elapsed)

  %GC time      40.4%  (40.7% elapsed)

  Alloc rate    446,776,113 bytes per MUT second

  Productivity  59.6% of total user, 58.6% of total elapsed


real    0m7.251s
user    0m7.120s
sys     0m0.058s


-------------- next part --------------
main = print ( inits1 [1..4000])

inits1:
./a.out +RTS -sstderr
1,400,787,732 bytes allocated in the heap
388,860,884 bytes copied during GC
    106,012 bytes maximum residency (364 sample(s))

       5343 collections in generation 0 (  1.94s)
        364 collections in generation 1 (  0.12s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.54s  (  4.49s elapsed)
  GC    time    2.06s  (  2.27s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    6.60s  (  6.76s elapsed)

  %GC time      31.2%  (33.6% elapsed)

  Alloc rate    308,543,553 bytes per MUT second

  Productivity  68.8% of total user, 67.2% of total elapsed


real    0m6.761s
user    0m6.606s
sys     0m0.065s


inits2:
./a.out +RTS -sstderr
1,303,507,236 bytes allocated in the heap
397,923,788 bytes copied during GC
    153,240 bytes maximum residency (352 sample(s))

       4972 collections in generation 0 (  2.06s)
        352 collections in generation 1 (  0.09s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.07s  (  4.45s elapsed)
  GC    time    2.15s  (  2.06s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    6.22s  (  6.51s elapsed)

  %GC time      34.6%  (31.6% elapsed)

  Alloc rate    320,272,048 bytes per MUT second

  Productivity  65.4% of total user, 62.5% of total elapsed


real    0m6.519s
user    0m6.226s
sys     0m0.113s



inits3:
./a.out +RTS -sstderr
1,303,667,780 bytes allocated in the heap
397,794,396 bytes copied during GC
    152,220 bytes maximum residency (352 sample(s))

       4973 collections in generation 0 (  1.88s)
        352 collections in generation 1 (  0.20s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.25s  (  4.80s elapsed)
  GC    time    2.08s  (  1.73s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    6.33s  (  6.53s elapsed)

  %GC time      32.9%  (26.5% elapsed)

  Alloc rate    306,745,360 bytes per MUT second

  Productivity  67.1% of total user, 65.1% of total elapsed


real    0m6.526s
user    0m6.338s
sys     0m0.101s
-------------- next part --------------
main = sum $ map sum $ subseqs [1..1000]
subseqs xs = [ ] : [t | i<-inits xs, t<-tails i, not (null t) ]

inits1:
./a.out +RTS -sstderr
1,424,286,576 bytes allocated in the heap
 17,410,888 bytes copied during GC
     56,944 bytes maximum residency (17 sample(s))

       5369 collections in generation 0 (  0.11s)
         17 collections in generation 1 (  0.00s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.99s  (  5.10s elapsed)
  GC    time    0.11s  (  0.14s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.10s  (  5.24s elapsed)

  %GC time       2.2%  (2.7% elapsed)

  Alloc rate    285,428,171 bytes per MUT second

  Productivity  97.8% of total user, 95.2% of total elapsed


real    0m5.236s
user    0m5.106s
sys     0m0.080s

inits2:
./a.out +RTS -sstderr
1,418,214,180 bytes allocated in the heap
 17,529,592 bytes copied during GC
     57,084 bytes maximum residency (17 sample(s))

       5346 collections in generation 0 (  0.03s)
         17 collections in generation 1 (  0.00s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    5.10s  (  5.08s elapsed)
  GC    time    0.03s  (  0.10s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    5.13s  (  5.18s elapsed)

  %GC time       0.6%  (1.9% elapsed)

  Alloc rate    278,081,211 bytes per MUT second

  Productivity  99.4% of total user, 98.5% of total elapsed


real    0m5.189s
user    0m5.132s
sys     0m0.029s


inits3:
./a.out +RTS -sstderr
1,418,217,652 bytes allocated in the heap
 17,461,052 bytes copied during GC
     56,828 bytes maximum residency (17 sample(s))

       5346 collections in generation 0 (  0.13s)
         17 collections in generation 1 (  0.00s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    5.13s  (  5.26s elapsed)
  GC    time    0.13s  (  0.14s elapsed)
  EXIT  time    0.01s  (  0.00s elapsed)
  Total time    5.27s  (  5.40s elapsed)

  %GC time       2.5%  (2.6% elapsed)

  Alloc rate    275,917,831 bytes per MUT second

  Productivity  97.5% of total user, 95.2% of total elapsed


real    0m5.403s
user    0m5.270s
sys     0m0.080s
-------------- next part --------------
main = print ( length $ subseqs [1..10000] )
inits1:
./a.out +RTS -sstderr
50005001
3,615,973,512 bytes allocated in the heap
982,547,684 bytes copied during GC
    226,180 bytes maximum residency (930 sample(s))

      13794 collections in generation 0 (  4.42s)
        930 collections in generation 1 (  0.51s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    5.67s  (  5.57s elapsed)
  GC    time    4.93s  (  5.23s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time   10.60s  ( 10.80s elapsed)

  %GC time      46.5%  (48.4% elapsed)

  Alloc rate    637,737,832 bytes per MUT second

  Productivity  53.5% of total user, 52.5% of total elapsed


real    0m10.804s
user    0m10.604s
sys     0m0.082s


inits2:

./a.out +RTS -sstderr
50005001
3,011,192,612 bytes allocated in the heap
1,162,573,012 bytes copied during GC
    334,036 bytes maximum residency (939 sample(s))

      11487 collections in generation 0 (  3.71s)
        939 collections in generation 1 (  1.02s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.70s  (  4.90s elapsed)
  GC    time    4.73s  (  4.71s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    9.43s  (  9.61s elapsed)

  %GC time      50.2%  (49.0% elapsed)

  Alloc rate    640,679,279 bytes per MUT second

  Productivity  49.8% of total user, 48.9% of total elapsed

real    0m9.612s
user    0m9.438s
sys     0m0.114s

inits3:
./a.out +RTS -sstderr
50005001
3,011,195,876 bytes allocated in the heap
1,163,335,136 bytes copied during GC
    331,672 bytes maximum residency (939 sample(s))

      11487 collections in generation 0 (  3.66s)
        939 collections in generation 1 (  0.83s)

          2 Mb total memory in use

  INIT  time    0.00s  (  0.00s elapsed)
  MUT   time    4.92s  (  4.84s elapsed)
  GC    time    4.49s  (  4.77s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    9.41s  (  9.61s elapsed)

  %GC time      47.7%  (49.6% elapsed)

  Alloc rate    612,031,682 bytes per MUT second

  Productivity  52.3% of total user, 51.2% of total elapsed


real    0m9.610s
user    0m9.416s
sys     0m0.130s
-------------- next part --------------
ghci

*Main> print (sum $ map sum $ inits1 [1..5000])
20845835000
(3.12 secs, 603772288 bytes)

*Main> print (sum $ map sum $ inits2 [1..5000])
20845835000
(5.74 secs, 602081548 bytes)

*Main> print (sum $ map sum $ inits3 [1..5000])
20845835000
(2.48 secs, 451953816 bytes)

*Main> print (length $ map sum $ inits1 [1..10000000])
10000001
(6.18 secs, 1928079404 bytes)

*Main> print (length $ map sum $ inits2 [1..10000000])
10000001
(15.44 secs, 1485182412 bytes)

*Main> print (length $ map sum $ inits3 [1..10000000])
10000001
(4.30 secs, 1526992312 bytes)

*Main> print (length $ inits1 [1..10000000])
10000001
(7.74 secs, 1563914564 bytes)

*Main> print (length $ inits2 [1..10000000])
10000001
(15.15 secs, 1123320716 bytes)

*Main> print (length $ inits3 [1..10000000])
10000001
(3.92 secs, 1162444200 bytes)

*Main> print (or $ concat $ inits1 $  ((replicate 20000 False) ++[True] ++ []  )  )
True
(17.64 secs, 9641524032 bytes)

*Main> print (or $ concat $ inits2 $  ((replicate 20000 False) ++[True] ++ []  )  )
True
(53.36 secs, 9630370716 bytes)

*Main> print (or $ concat $ inits3 $  ((replicate 20000 False) ++[True] ++ []  )  )
True
(10.42 secs, 7225509420 bytes)


More information about the Libraries mailing list