Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounded cache #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt Bench.hs to the bounded caches.
DataCache.lookup now has result Maybe (res a, DataCache res) instead of
Maybe (res a).
Philipp Kant committed Jul 9, 2015
commit d41255bfd0a4990e6fdbc21ba2d6f5a3c763ee48
8 changes: 7 additions & 1 deletion tests/Bench.hs
Original file line number Diff line number Diff line change
@@ -30,17 +30,23 @@ instance Hashable (TestReq a) where
hashWithSalt salt (ReqDouble i) = hashWithSalt salt (1::Int, i)
hashWithSalt salt (ReqBool i) = hashWithSalt salt (2::Int, i)

instance CacheableSource TestReq

main = do
[n] <- fmap (fmap read) getArgs
t0 <- getCurrentTime
let
lookup r c = case DataCache.lookup r c of
Nothing -> Nothing
Just (res, _) -> Just res

f 0 !cache = return cache
f !n !cache = do
m <- newResult 0
f (n-1) (DataCache.insert (ReqInt n) m cache)
--
cache <- f n DataCache.empty
let m = DataCache.lookup (ReqInt (n `div` 2)) cache
let m = lookup (ReqInt (n `div` 2)) cache
print =<< mapM takeResult m
t1 <- getCurrentTime
printf "insert: %.2fs\n" (realToFrac (t1 `diffUTCTime` t0) :: Double)