Proposal (Trac ticket #3671): Add takeRec,
genericTakeRec and spanRec to Data.List
Malcolm Wallace
malcolm.wallace at cs.york.ac.uk
Wed Nov 18 23:14:45 EST 2009
> take+drop combination should be slower than splitAt
I suppose the only convincing argument is empirical. Using the
following simple and unscientific benchmark, it turns out that take
+drop is ~ 2x faster than splitAt. Maybe list fusion or something is
kicking in.
main = do print (length (splitAts 15 bigList))
main' = do print (length (groupsOf 15 bigList))
bigList = replicate 15000000 ()
groupsOf n = takeWhile (not . null) . map (take n) . iterate
(drop n)
splitAts n [] = []
splitAts n xs = let (a,b) = splitAt n xs in a: splitAts n b
time ./groupsOf
1000000
real 0m0.234s
user 0m0.225s
sys 0m0.006s
time ./splitAts
1000000
real 0m0.557s
user 0m0.542s
sys 0m0.012s
Regards,
Malcolm
More information about the Libraries
mailing list