Skip to content

Instantly share code, notes, and snippets.

@MarcelineVQ
Created April 28, 2020 11:56
Show Gist options
  • Select an option

  • Save MarcelineVQ/b3a1469b9371155e7fb7ab34d6f3d29d to your computer and use it in GitHub Desktop.

Select an option

Save MarcelineVQ/b3a1469b9371155e7fb7ab34d6f3d29d to your computer and use it in GitHub Desktop.
%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