1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import System.Random
import Test.Tasty.Bench
import qualified KWay.PrioMergeAlg as KWay
import qualified PHeapSort as HS
import qualified Data.PQueue.Prio.Min as P
kWay :: Int -> Int -> Benchmark
kWay i n = bench
("k-way merge looking " ++ show i ++ " deep into " ++ show n ++ " streams")
(whnf ((!! i) . KWay.merge . KWay.mkStreams n) $ mkStdGen 5466122035931067691)
hSort :: Int -> Benchmark
hSort n = bench
("Heap sort with " ++ show n ++ " elements")
(nf (HS.heapSortRandoms n) $ mkStdGen (-7750349139967535027))
filterQ :: Int -> Benchmark
filterQ n = bench
("filter with " ++ show n ++ " elements")
(whnf (P.drop 1 . P.filterWithKey (>) . (P.fromList :: [(Int, Int)] -> P.MinPQueue Int Int) . take n . randoms) $ mkStdGen 977209486631198655)
partitionQ :: Int -> Benchmark
partitionQ n = bench
("partition with " ++ show n ++ " elements")
(whnf (P.drop 1 . snd . P.partitionWithKey (>) . (P.fromList :: [(Int, Int)] -> P.MinPQueue Int Int) . take n . randoms) $ mkStdGen 781928047937198)
main :: IO ()
main = defaultMain
[ bgroup "heapSort"
[ hSort (10^3)
, hSort (10^4)
, hSort (10^5)
, hSort (10^6)
, hSort (3*10^6)
]
, bgroup "kWay"
[ kWay (10^3) 1000000
, kWay (10^5) 1000
, kWay (10^5) 10000
, kWay (10^5) 100000
, kWay (10^6) 1000
, kWay (10^6) 10000
, kWay (10^6) 20000
, kWay (3*10^6) 1000
, kWay (2*10^6) 2000
, kWay (4*10^6) 100
]
, bgroup "filter"
[ filterQ (10^3)
, filterQ (10^4)
, filterQ (10^5)
, filterQ (10^6)
, filterQ (3*10^6)
]
, bgroup "partition"
[ partitionQ (10^3)
, partitionQ (10^4)
, partitionQ (10^5)
, partitionQ (10^6)
, partitionQ (3*10^6)
]
]
|