Created
January 26, 2017 11:57
-
-
Save snoyberg/6a48876aedb9b19c808a0c53e86109ac to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env stack | |
-- stack --resolver lts-7.14 --install-ghc exec -- ghc -O2 -with-rtsopts=-s | |
import Control.Monad.ST | |
import Data.STRef | |
a k x1 x2 x3 x4 x5 = | |
do kk <- newSTRef k | |
let b = do k <- modifySTRef kk pred >> readSTRef kk; a k b x1 x2 x3 x4 | |
if k <= 0 then do x3' <- x3; x4' <- x4; return (x3' + x4') | |
else do x5' <- x5; b' <- b; return (x5' + b') | |
main = print (runST (a 22 (return 1) (return (-1)) (return (-1)) (return 1) (return 0))) |
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
#!/usr/bin/env stack | |
-- stack --resolver lts-7.14 --install-ghc exec -- ghc -O2 -with-rtsopts=-s | |
import Control.Monad.ST | |
import Data.STRef | |
a k x1 x2 x3 x4 x5 = | |
do kk <- newSTRef k | |
let b = do k <- modifySTRef' kk pred >> readSTRef kk; a k b x1 x2 x3 x4 | |
if k <= 0 then do x3' <- x3; x4' <- x4; return (x3' + x4') | |
else do x5' <- x5; b' <- b; return (x5' + b') | |
main = print (runST (a 22 (return 1) (return (-1)) (return (-1)) (return 1) (return 0))) |
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
#!/usr/bin/env stack | |
-- stack --resolver lts-7.14 --install-ghc exec -- ghc -O2 -with-rtsopts=-s | |
import Control.Monad.ST | |
import Data.STRef | |
a :: Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
a k x1 x2 x3 x4 x5 = | |
do kk <- newSTRef k | |
let b = do k <- modifySTRef' kk pred >> readSTRef kk; a k b x1 x2 x3 x4 | |
if k <= 0 then do x3' <- x3; x4' <- x4; return (x3' + x4') | |
else do x5' <- x5; b' <- b; return (x5' + b') | |
main = print (runST (a 22 (return 1) (return (-1)) (return (-1)) (return 1) (return 0))) |
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
#!/usr/bin/env stack | |
-- stack --resolver lts-7.14 --install-ghc exec -- ghc -O2 -with-rtsopts=-s | |
import Control.Monad.ST | |
import Data.STRef | |
a :: Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
a k x1 x2 x3 x4 x5 = | |
do kk <- newSTRef k | |
let b = do k <- modifySTRef' kk (subtract 1) >> readSTRef kk; a k b x1 x2 x3 x4 | |
if k <= 0 then do x3' <- x3; x4' <- x4; return (x3' + x4') | |
else do x5' <- x5; b' <- b; return (x5' + b') | |
main = print (runST (a 22 (return 1) (return (-1)) (return (-1)) (return 1) (return 0))) |
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
#!/usr/bin/env stack | |
-- stack --resolver lts-7.14 --install-ghc exec -- ghc -O2 -with-rtsopts=-s | |
import Control.Monad.ST | |
import Data.STRef | |
a :: Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
-> ST s Int | |
a k x1 x2 x3 x4 x5 = | |
do kk <- newSTRef k | |
let b = do k <- modifySTRef' kk (subtract 1) >> readSTRef kk; a k b x1 x2 x3 x4 | |
if k <= 0 then do x3' <- x3; x4' <- x4; return $! x3' + x4' | |
else do x5' <- x5; b' <- b; return $! x5' + b' | |
main = print (runST (a 22 (return 1) (return (-1)) (return (-1)) (return 1) (return 0))) |
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
Original version: | |
-14254067 | |
4,907,852,080 bytes allocated in the heap | |
5,442,629,272 bytes copied during GC | |
1,121,103,736 bytes maximum residency (13 sample(s)) | |
27,788,856 bytes maximum slop | |
2201 MB total memory in use (0 MB lost due to fragmentation) | |
Tot time (elapsed) Avg pause Max pause | |
Gen 0 9367 colls, 0 par 2.344s 2.428s 0.0003s 0.0049s | |
Gen 1 13 colls, 0 par 2.672s 5.098s 0.3922s 2.9496s | |
INIT time 0.000s ( 0.002s elapsed) | |
MUT time 2.413s ( 3.051s elapsed) | |
GC time 5.016s ( 7.527s elapsed) | |
EXIT time 0.021s ( 0.229s elapsed) | |
Total time 7.451s ( 10.809s elapsed) | |
%GC time 67.3% (69.6% elapsed) | |
Alloc rate 2,033,853,020 bytes per MUT second | |
Productivity 32.7% of total user, 22.5% of total elapsed | |
modifySTRef': | |
-14254067 | |
3,932,003,776 bytes allocated in the heap | |
5,720,188,216 bytes copied during GC | |
1,263,737,656 bytes maximum residency (13 sample(s)) | |
25,694,112 bytes maximum slop | |
2475 MB total memory in use (0 MB lost due to fragmentation) | |
Tot time (elapsed) Avg pause Max pause | |
Gen 0 7498 colls, 0 par 2.294s 2.454s 0.0003s 0.0100s | |
Gen 1 13 colls, 0 par 2.702s 4.047s 0.3113s 2.1148s | |
INIT time 0.000s ( 0.003s elapsed) | |
MUT time 2.379s ( 3.432s elapsed) | |
GC time 4.997s ( 6.501s elapsed) | |
EXIT time 0.022s ( 0.249s elapsed) | |
Total time 7.399s ( 10.186s elapsed) | |
%GC time 67.5% (63.8% elapsed) | |
Alloc rate 1,652,871,915 bytes per MUT second | |
Productivity 32.5% of total user, 23.6% of total elapsed | |
Add Int type signature: | |
-14254067 | |
4,004,140,832 bytes allocated in the heap | |
4,068,947,688 bytes copied during GC | |
695,459,136 bytes maximum residency (12 sample(s)) | |
25,423,360 bytes maximum slop | |
1363 MB total memory in use (0 MB lost due to fragmentation) | |
Tot time (elapsed) Avg pause Max pause | |
Gen 0 7631 colls, 0 par 2.047s 2.075s 0.0003s 0.0024s | |
Gen 1 12 colls, 0 par 1.093s 1.653s 0.1377s 0.7375s | |
INIT time 0.000s ( 0.002s elapsed) | |
MUT time 1.603s ( 1.502s elapsed) | |
GC time 3.140s ( 3.728s elapsed) | |
EXIT time 0.019s ( 0.155s elapsed) | |
Total time 4.762s ( 5.387s elapsed) | |
%GC time 65.9% (69.2% elapsed) | |
Alloc rate 2,497,881,075 bytes per MUT second | |
Productivity 34.1% of total user, 30.1% of total elapsed | |
Replace pred with subtract 1: no change | |
Strict return | |
-14254067 | |
2,703,009,728 bytes allocated in the heap | |
7,033,480 bytes copied during GC | |
64,544 bytes maximum residency (3 sample(s)) | |
74,032 bytes maximum slop | |
2 MB total memory in use (0 MB lost due to fragmentation) | |
Tot time (elapsed) Avg pause Max pause | |
Gen 0 5154 colls, 0 par 0.024s 0.029s 0.0000s 0.0006s | |
Gen 1 3 colls, 0 par 0.000s 0.004s 0.0014s 0.0040s | |
INIT time 0.000s ( 0.002s elapsed) | |
MUT time 0.862s ( 0.883s elapsed) | |
GC time 0.025s ( 0.033s elapsed) | |
EXIT time 0.000s ( 0.000s elapsed) | |
Total time 0.887s ( 0.919s elapsed) | |
%GC time 2.8% (3.6% elapsed) | |
Alloc rate 3,137,008,592 bytes per MUT second | |
Productivity 97.2% of total user, 93.9% of total elapsed | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment