Ticket #45 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

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

Changed 3 years ago by rl

  • milestone changed from 0.8 to 0.7.1

Changed 3 years ago by rl

  • priority changed from major to critical

Changed 3 years ago by rl

  • status changed from new to closed
  • resolution set to invalid

I can't reproduce this, the first version is about 2x faster than the second one. Boxed vectors a about 3x slower but that is to be expected.

Note: See TracTickets for help on using tickets.