[Haskell-cafe] timing question

Arie Groeneveld bradypus at xs4all.nl
Tue Aug 5 03:15:57 EDT 2008


Acc. to Luke Palmers suggestion this will be the right answer?

*Main> seqList rwhnf(map f $ concat.replicate 1000000 $ unfoldr (knip 6) an)
()
(3.46 secs, 834240864 bytes)

or with/without  list construction

*Main> let ry = concat.replicate 1000000 $ unfoldr (knip 6) an
(0.00 secs, 0 bytes)
*Main> seqList rwhnf(map f ry)
()
(4.48 secs, 833668720 bytes)
*Main> seqList rwhnf(map f ry)
()
(3.18 secs, 627071612 bytes)
*Main>



Arie Groeneveld schreef:
> Thanks for all the advises so far.
>
> Ok, here's my monster that need to be timed in order to make a comparison:
> (it's about the control digit of SEDOL numbers  
> http://en.wikipedia.org/wiki/SEDOL ):
>
>
> knip _ [] = Nothing
> knip k xs = Just (splitAt k xs)
>
> ip xs = sum . zipWith (*) xs
>
> an =  ['0'..'9']++['A'..'Z']
>
> s = take 841 $ cycle "0987654321"
> f = \xs -> xs ++ [(sna!!).ip [1,3,1,7,3,9]. map (flip (fromJust .) an 
> . findIndex . (==))$xs]
>
>
>
> Here's my try for timing:
>
> *Main> (foldl1 (\x y -> f y) .concat.replicate 1000000 $ unfoldr (knip 
> 6) an)
> "UVWXYZ7"
> (1.31 secs, 330291000 bytes)
>
> (It's incl. the construction of the test list, as is in the language 
> to compare )
>
> I need the whole list to be evaluated.
> Interpreted mode IS A MUST :-)
>
> BTW I increased stack size
>
>
> thanks
>
>
> Don Stewart schreef:
>> bradypus:
>>   
>>> Suppose I've:
>>>
>>> f = map g
>>>
>>> I want to know how much time it takes (interpreted mode) to fully 
>>> process list xs (at least 1e6 elements) with function g. Is it 
>>> sufficient to execute:
>>>
>>> *Main> last . f $ xs
>>> <result>
>>> (x.xx secs, yyyyyyyyyyy bytes)
>>>
>>> Are there any hidden difficulties involved?
>>>
>>> Reason is: comparing timings Haskell vs an interpreted language without 
>>> laziness.
>>>
>>>     
>>
>> If you care about timings, it's probably a better idea to compile the
>> code (with optimisations on), to get a better idea of what the code
>> would do in a production environment.
>>
>> You could then just time the binary,
>>
>>     main = print . sum $ ....
>>
>>     ghc -O2 A.hs --make
>>     time ./A
>>
>> -- Don
>>
>>
>>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080805/0db0ca13/attachment-0001.htm


More information about the Haskell-Cafe mailing list