#2271: floor, ceiling, round :: Double -> Int are awesomely slow
------------------------------------------+---------------------------------
    Reporter:  dons                       |        Owner:              
        Type:  bug                        |       Status:  new         
    Priority:  low                        |    Milestone:  7.0.1       
   Component:  libraries/base             |      Version:  6.8.2       
    Keywords:  performance, math, double  |     Testcase:              
   Blockedby:                             |   Difficulty:  Unknown     
          Os:  Unknown/Multiple           |     Blocking:              
Architecture:  Unknown/Multiple           |      Failure:  None/Unknown
------------------------------------------+---------------------------------

Comment(by daniel.is.fischer):

 I have put together a package to test possible implementations of
 the RealFrac methods for Double and Float (base-2 IEEE754).

 On the one hand, pure Haskell implementations, on the other hand
 implementations calling out to rint[f], trunc[f], floor[f] and ceil[f]
 from math.h.

 Both ways go via Integer by default, with a specialised faster
 implementation
 for Int (and narrower types, but those RULES haven't yet been written)
 enabled by a rewrite rule.

 Overall, the pure Haskell implementations don't fare badly on my computer.
 All give a speedup compared to the current implementation, for most
 conversions, pure Haskell is on par with or faster than the C-call
 (although that would probably change if the C functions were made
 primops).

 The FFI calls are significantly faster for
 properFraction :: Double -> (Integer, Double)
 and for round (except round :: Integral a => Float -> a when compiled via
 C,
 then native and FFI are on par).

 Sample results for the speedups against the current implementation (note:
 for truncate :: x -> Int, the Prelude value is fst . properFraction, not
 the rewritten float2Int or double2Int) are included in the tarball.

 I would appreciate feedback from your tests/benchmarks on other platforms,
 especially 64-bit platforms (mine is x86 linux, 32 bit).

 To run the QuickCheck tests, you need QuickCheck-2.*, to run the
 benchmarks,
 criterion.

 More instructions in the README.

 Thanks,
 Daniel

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2271#comment:13>
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