Ticket #45 (closed defect: invalid)
fromList/sort performance problems
| Reported by: | rl | Owned by: | |
|---|---|---|---|
| Priority: | critical | Milestone: | 0.7.1 |
| Version: | 0.7 | Keywords: | |
| Cc: |
Description
Reportedly, this is slow:
import Prelude hiding (sum) import Data.Vector.Algorithms.Combinators (apply) import Data.Vector.Algorithms.Intro (sort) import Data.Vector.Unboxed (Vector, Unbox, fromList, sum) vsort :: (Unbox a, Ord a) => [a] -> Vector a vsort = apply sort . fromList list :: [Int] list = takeWhile (> 0) $ iterate (subtract 1) 10000000 main = do print $ sum $ vsort list
And this is fast:
import Prelude hiding (sum) import Control.Monad (zipWithM_) import Data.Vector.Algorithms.Intro (sort) import Data.Vector.Generic (create) import Data.Vector.Unboxed (Vector, Unbox, sum) import Data.Vector.Unboxed.Mutable (new, write) vsort :: (Unbox a, Ord a) => [a] -> Vector a vsort list = create $ do v <- new (length list) zipWithM_ (\i x -> write v i x) [0..] list sort v return v list :: [Int] list = takeWhile (> 0) $ iterate (subtract 1) 10000000 main = do print $ sum $ vsort list
Also, boxed vector seem to kill performance here.
Change History
Note: See
TracTickets for help on using
tickets.
