Proposal (Trac ticket #3671): Add takeRec, genericTakeRec and spanRec to Data.List

Malcolm Wallace malcolm.wallace at
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
real	0m0.234s
user	0m0.225s
sys	0m0.006s

time ./splitAts
real	0m0.557s
user	0m0.542s
sys	0m0.012s


More information about the Libraries mailing list