
19 Nov
2009
19 Nov
'09
4:14 a.m.
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