#1434: Slow conversion from Double to Int
----------------------------------------+-----------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.4.1
Severity: normal | Keywords:
Difficulty: Unknown | Os: Linux
Testcase: | Architecture: Unknown
----------------------------------------+-----------------------------------
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.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1434>
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