Ticket #32 (closed defect: fixed)
Performance of concatMap and O2/Odph
| Reported by: | choener | Owned by: | |
|---|---|---|---|
| Priority: | critical | Milestone: | 0.7.1 |
| Version: | 0.6 | Keywords: | |
| Cc: |
Description
This one is fun, I get slowdowns of up to 10.000x which is especially nice in code that is called often ;-) (why exactly, I do not know yet, it should be more like x5 - 10x) -Odph adversely effects runtime performance here!
The code below differs only in the "makes it slow" line.
module Main where
import qualified Data.Vector.Unboxed as VU
import Criterion.Main
iL = 4
jL = 100
good :: Int -> Int -> VU.Vector (Int,Int)
good i j = {-# CORE "good" #-}
VU.map (\(k,l) -> (k-l,l)) $
VU.concatMap (
\d -> VU.map (\d' -> (d,d'))
$ VU.enumFromN 3 (d-5)) -- for each distance, all possible left/right combinations
$ VU.enumFromN 8 (min 23 (j-i-13)) -- diagonal distance or number of unpaired nucleotides -2.
{-# INLINE good #-}
bad :: Int -> Int -> VU.Vector (Int,Int)
bad i j = {-# CORE "bad" #-}
VU.map (\(k,l) -> (i+k,j-l)) $ -- this part makes it slow!
VU.map (\(k,l) -> (k-l,l)) $
VU.concatMap (
\d -> VU.map (\d' -> (d,d'))
$ VU.enumFromN 3 (d-5)) -- for each distance, all possible left/right combinations
$ VU.enumFromN 8 (min 23 (j-i-13)) -- diagonal distance or number of unpaired nucleotides -2.
{-# INLINE bad #-}
main = defaultMain
[ bench "good" $ whnf (\j -> VU.sum $ VU.map (\(k,l) -> k+l) $ good iL j) jL
, bench "bad" $ whnf (\j -> VU.sum $ VU.map (\(k,l) -> k+l) $ bad iL j) jL
]
Change History
Note: See
TracTickets for help on using
tickets.
