Last active
February 18, 2023 23:29
-
-
Save AndreasPK/2e2cec5b8845c820afdb0d8a6a9723af to your computer and use it in GitHub Desktop.
Unknown call overhead.
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
module Lib where | |
import Data.Vector as V | |
type LookupCached a = Int -> a | |
mkCache :: [a] -> LookupCached a | |
mkCache xs = | |
let !cache = V.fromList xs | |
in V.unsafeIndex cache | |
type CachedList1 a = Vector a | |
mkCache2 :: [a] -> CachedList1 a | |
mkCache2 xs = V.fromList xs | |
lookupCache :: CachedList1 a -> Int -> a | |
lookupCache !cache !i = V.unsafeIndex cache i |
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
{-# OPTIONS_GHC -O2 -fproc-alignment=64 #-} | |
import Criterion.Main | |
import Lib | |
index = 1 :: Int | |
-- Our benchmark harness. | |
main = defaultMain [ | |
bgroup "vec-cache" | |
[ env | |
(pure $ mkCache $ [0..1000::Int] ) | |
(\cache -> bench "higher-order" $ whnf cache index) | |
, env | |
(pure $ mkCache2 $ [0..1000::Int] ) | |
(\cache -> bench "defunctionalized" $ whnf (lookupCache cache) index) | |
] | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment