-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hstream-store: add listStreamPartitionsOrderedByName (#1755)
* add listStreamPartitionsOrderedByName * add a SortBench.hs --------- Co-authored-by: YangKian <[email protected]>
- Loading branch information
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
|
||
module Main where | ||
|
||
import Control.Monad | ||
import Criterion.Main | ||
import qualified Data.List as L | ||
import qualified Data.Vector as V | ||
import qualified Data.Vector.Algorithms.Intro as V | ||
import System.Random (randomRIO) | ||
|
||
sortList :: [Int] -> IO [Int] | ||
sortList xs = pure $! L.sort xs | ||
|
||
sortVectorIntro :: V.Vector Int -> IO (V.Vector Int) | ||
sortVectorIntro xs = do | ||
!mvec <- V.unsafeThaw xs | ||
V.sort mvec | ||
V.unsafeFreeze mvec | ||
|
||
--ys :: | ||
|
||
main :: IO () | ||
main = do | ||
let n = 1000000 | ||
let !xs1 = [0..n] | ||
!ys1 = V.fromList xs1 | ||
!xs2 = [n..0] | ||
!ys2 = V.fromList xs2 | ||
|
||
-- n(1000000) is too many for generate random numbers, so we use 10000 instead. | ||
!xs3 <- replicateM 10000 $ randomRIO (0, n :: Int) | ||
let !ys3 = V.fromList xs3 | ||
|
||
defaultMain | ||
[ bgroup "sort1" [ bench "List" $ nfIO (sortList xs1) | ||
, bench "Vector.Algorithms.Intro" $ nfIO (sortVectorIntro ys1) | ||
] | ||
, bgroup "sort2" [ bench "List" $ nfIO (sortList xs2) | ||
, bench "Vector.Algorithms.Intro" $ nfIO (sortVectorIntro ys2) | ||
] | ||
, bgroup "sort3" [ bench "List" $ nfIO (sortList xs3) | ||
, bench "Vector.Algorithms.Intro" $ nfIO (sortVectorIntro ys3) | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters