Created
April 28, 2020 11:56
-
-
Save MarcelineVQ/b3a1469b9371155e7fb7ab34d6f3d29d 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
| %foreign "scheme:chez,real-time" | |
| "scheme:racket,current-milliseconds" | |
| time' : PrimIO Int | |
| getTime : IO Int | |
| getTime = primIO time' | |
| export | |
| foo : IO Int -- records time properly, roughly 2 seconds of work | |
| foo = do | |
| t1 <- getTime | |
| pure $ foldl (+) (the Int 0) [1..10000000] | |
| t2 <- getTime | |
| pure (t2-t1) | |
| foo2helper : IO a -> IO Int | |
| foo2helper act = do | |
| t1 <- getTime | |
| act | |
| t2 <- getTime | |
| pure (t2-t1) | |
| foo2 : IO Int -- records time wrongly, records 0-1 milliseconds of work | |
| foo2 = foo2helper (pure $ foldl (+) (the Int 0) [1..10000000]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment