[Haskell-beginners] decorate-sort-undecorate in haskell

Ivan Uemlianin ivan at llaisdy.com
Tue Jun 23 10:20:34 EDT 2009


Daniel Fischer wrote:
> Prelude> :set +s
> Prelude> let lens :: [Int]; lens = [(k^2+3*k-2) `mod` 5431 | k <- [1 .. 500]]
> (0.04 secs, 6184112 bytes)
> Prelude> let lists = map (flip replicate ()) lens
> (0.00 secs, 609084 bytes)
> Prelude> :m +Data.List
> Prelude Data.List> :m +Data.Ord
> Prelude Data.List Data.Ord> let srtl1 = sortBy (comparing length) lists
> (0.00 secs, 0 bytes)
> Prelude Data.List Data.Ord> let srtl2 = map snd . sortBy (comparing fst) $ map (\l -> 
> (length l, l)) lists
> (0.02 secs, 5975640 bytes)
> Prelude Data.List Data.Ord> length (srtl2 !! 420)
> 4471
> (0.19 secs, 37089168 bytes)
> Prelude Data.List Data.Ord> length (srtl1 !! 420)
> 4471
> (1.09 secs, 542788 bytes)
>   
Profiling too!  Excellent.  So this shows that with these long lists of 
lists, the dsu version was about ten times faster.

I'll report back once I've written up.

Thanks to everyone for your comments.

Ivan

-- 
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development

                    ivan at llaisdy.com
                     www.llaisdy.com
                         llaisdy.wordpress.com
                     www.linkedin.com/in/ivanuemlianin

    "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
                     (Schiller, Beethoven)
============================================================



More information about the Beginners mailing list