Created
July 30, 2018 23:25
-
-
Save chessai/47eef4c45487c8d04f21edad4736ffec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# OPTIONS_GHC -O2 -fforce-recomp #-} | |
module Main (main) where | |
import Criterion.Main | |
import Control.Monad | |
import Data.Int | |
import Data.Vector (Vector) | |
import qualified Data.Vector as Vector | |
import Control.DeepSeq ( ($!!) ) | |
main :: IO () | |
main = do | |
bs :: Vector Int <- pure $!! Vector.fromList [1..5000] | |
defaultMain | |
[ bgroup "fmap bench" | |
[ bench "FMAP (LAZY)" $ nf (fmap (+1)) bs | |
, bench "FMAP (STRICT)" $ nf (fmap' (+1)) bs | |
] | |
] | |
fmap' :: Monad m => (a -> b) -> m a -> m b | |
fmap' f m = m >>= \ !x -> pure $! f x | |
{-# INLINE fmap' #-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment