-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from emiflake/emiflake/bench
add contrived benchmark
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
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,34 @@ | ||
module Main (main) where | ||
|
||
import Criterion (bench, bgroup, env) | ||
import Criterion.Main (defaultMain, whnf) | ||
import Data.Series (Series, series) | ||
import Data.Series qualified as Series | ||
import Data.Time (Day (ModifiedJulianDay), UTCTime (UTCTime), secondsToDiffTime) | ||
import Naive qualified | ||
|
||
mkUTCTime :: Integral a => a -> UTCTime | ||
mkUTCTime x = | ||
UTCTime | ||
(ModifiedJulianDay $ toInteger x `div` 86401) | ||
(secondsToDiffTime $ toInteger x `mod` 86401) | ||
|
||
setupEnv :: IO (Series Int, Naive.Series Int) | ||
setupEnv = do | ||
let largeSeries :: Series Int | ||
largeSeries = series [(mkUTCTime x, x) | x <- [0 .. 1000000]] | ||
|
||
naiveLargeSeries :: Naive.Series Int | ||
naiveLargeSeries = Naive.series [(mkUTCTime x, x) | x <- [0 .. 1000000]] | ||
pure (largeSeries, naiveLargeSeries) | ||
|
||
main :: IO () | ||
main = | ||
defaultMain | ||
[ env setupEnv $ \ ~(largeSeries, naiveLargeSeries) -> | ||
bgroup | ||
"slice" | ||
[ bench "series" $ whnf (Series.slice (mkUTCTime @Int 50000) (mkUTCTime @Int 100000)) largeSeries | ||
, bench "naive" $ whnf (Naive.slice (mkUTCTime @Int 50000) (mkUTCTime @Int 100000)) naiveLargeSeries | ||
] | ||
] |
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,22 @@ | ||
module Naive (Series (..), slice, series) where | ||
|
||
import Control.DeepSeq (NFData) | ||
import Data.Kind (Type) | ||
import Data.Series (DataPoint (DataPoint)) | ||
import Data.Time (UTCTime) | ||
import GHC.Generics (Generic) | ||
|
||
newtype Series (a :: Type) = Series [DataPoint a] | ||
deriving stock (Show, Eq, Generic) | ||
deriving newtype (NFData) | ||
|
||
slice :: | ||
forall (a :: Type). | ||
UTCTime -> | ||
UTCTime -> | ||
Series a -> | ||
Series a | ||
slice start end (Series xs) = Series [DataPoint x y | DataPoint x y <- xs, x >= start && x <= end] | ||
|
||
series :: [(UTCTime, a)] -> Series a | ||
series = Series . fmap (uncurry DataPoint) |
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