Ticket #1434 (closed task: fixed)
Missing RULEs for truncate
| Reported by: | ghc@… | Owned by: | simonmar |
|---|---|---|---|
| Priority: | high | Milestone: | 7.0.1 |
| Component: | libraries/base | Version: | 6.4.1 |
| Keywords: | rules | Cc: | ghc-bug@…, dons@…, alexey.skladnoy@… |
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | Runtime performance bug | Difficulty: | Unknown |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description
I found that the rounding functions from RealFrac? class are considerably slower than the low level functions from GHC.Float. This is really a problem for me when doing signal processing, since for writing to a common audio file format or listening to a signal data has to be converted from Double to Int16.
$ ghci +RTS -M256m -c30 -RTS ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.4.1, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base-1.0 ... linking ... done. Prelude> :set +s Prelude> sum $ map round [0.1,0.32..100000] :: Int 1252489463 (6.50 secs, 241894764 bytes) Prelude> sum $ map floor [0.1,0.32..100000] :: Int 1252262188 (6.07 secs, 240099200 bytes) Prelude> sum $ map ceiling [0.1,0.32..100000] :: Int 1252716734 (6.13 secs, 243795404 bytes) Prelude> sum $ map truncate [0.1,0.32..100000] :: Int 1252262188 (6.76 secs, 234572324 bytes) Prelude> sum $ map GHC.Float.double2Int [0.1,0.32..100000] :: Int 1252262188 (1.38 secs, 66137016 bytes)
As far as I can judge, double2Int does the same like truncate. Instead of using the methods from RealFrac? I could simply use double2Int but I consider this a work-around.
In GHC-6.6.1 these examples end with a stack overflow, but if I shorten the list, the time relations remain the same.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

