#3339: Data.Monoid: Add (<>) as a synonym for mappend
-----------------------------+----------------------------------------------
  Reporter:  bos             |          Owner:                  
      Type:  proposal        |         Status:  new             
  Priority:  normal          |      Milestone:  Not GHC         
 Component:  libraries/base  |        Version:  6.10.3          
Resolution:                  |       Keywords:                  
  Testcase:                  |      Blockedby:                  
Difficulty:  Unknown         |             Os:  Unknown/Multiple
  Blocking:                  |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown    |  
-----------------------------+----------------------------------------------

Comment(by nominolo):

 Benchmarks checking whether changing associativity of (<>) in `pretty`
 would lead to performance issues:

 {{{
 import Text.PrettyPrint

 import Data.List
 import Criterion.Main


 f_left :: Int -> Doc
 f_left n = foldl' (<>) empty (map (text . show) [10001..10000+n])

 f_right :: Int -> Doc
 f_right n = foldr (<>) empty (map (text . show) [10001..10000+n])

 main =
   defaultMain $
     [ bench "left"     $ nf (length . render . f_left)  10000
     , bench "right"    $ nf (length . render . f_right) 10000
     , bench "left20k"  $ nf (length . render . f_left)  20000
     , bench "right20k" $ nf (length . render . f_right) 20000
     , bench "left30k"  $ nf (length . render . f_left)  30000
     , bench "right30k" $ nf (length . render . f_right) 30000
     ]
 }}}

 Results (lower numbers are better):

 {{{
        Iterations
       _10K__________20K__________30K________
 Left   10.1 (0.5)   24.4 (0.6)   40.0 (1.3)
 Right   8.9 (0.2)   22.7 (3.1)   31.2 (4.6)

 Format:  runtime (stddev) all in milliseconds
 }}}

 So switching to right-associativity may actually increase performance
 slightly.  Scaling doesn't seem to be quite linear, but that could be due
 to cache effects or suchlike; and it's also outside the scope of this
 proposal.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3339#comment:22>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to