#1434: Slow conversion from Double to Int
---------------------------------------+------------------------------------
 Reporter:  [EMAIL PROTECTED]  |          Owner:  dons      
     Type:  bug                        |         Status:  new       
 Priority:  normal                     |      Milestone:  6.8 branch
Component:  libraries/base             |        Version:  6.4.1     
 Severity:  normal                     |     Resolution:            
 Keywords:                             |     Difficulty:  Unknown   
 Testcase:                             |   Architecture:  Unknown   
       Os:  Linux                      |  
---------------------------------------+------------------------------------
Changes (by dons):

  * owner:  => dons
 * cc: [EMAIL PROTECTED] (added)

Comment:

 I looked into this after the realToFrac issues last week. It's a similar
 story -- the noop rules are currently only set up for Int conversions.

 So, for example, this program:

 {{{
 import Data.Word
 import Data.Array.Vector

 main = print . sumU
              . mapU (truncate::Double->Word16)
              $ (enumFromToFracU 0.1 (100000000 :: Double))
 }}}

 truncate stays as a call to properFraction.

 Now, we can add some rules for this stuff:

 {{{
 {-# RULES
 "truncate/Double->Int64"
     truncate = fromIntegral . double2Int :: Double -> Int64
 "truncate/Double->Int32"
     truncate = fromIntegral . double2Int :: Double -> Int32
 "truncate/Double->Int16"
     truncate = fromIntegral . double2Int :: Double -> Int16
 "truncate/Double->Int8"
     truncate = fromIntegral . double2Int :: Double -> Int8
 "truncate/Double->Word64"
     truncate = fromIntegral . double2Int :: Double -> Word64
 "truncate/Double->Word32"
     truncate = fromIntegral . double2Int :: Double -> Word32
 "truncate/Double->Word16"
     truncate = fromIntegral . double2Int :: Double -> Word16
 "truncate/Double->Word8"
     truncate = fromIntegral . double2Int :: Double -> Word8
   #-}
 }}}

 And the running time drops from:

 {{{
 $ time ./henning
 28800
 ./henning  45.84s user 0.11s system 98% cpu 46.448 total
 }}}

 before, to:

 {{{
 $ time ./henning
 28800
 ./henning  0.39s user 0.00s system 97% cpu 0.398 total
 }}}

 after.

 I think this is as good a time as any to do an audit of the Int/noop
 conversion rules
 in base, looking for others that also should work for integral types. I'll
 take care of this.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1434#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to