Skip to content

Instantly share code, notes, and snippets.

@jkachmar
Last active August 30, 2018 17:52
Show Gist options
  • Save jkachmar/ff2db4d607c68f08bd4b6bed71b3c631 to your computer and use it in GitHub Desktop.
Save jkachmar/ff2db4d607c68f08bd4b6bed71b3c631 to your computer and use it in GitHub Desktop.
benchmarked CPS/10
time 15.54 ns (14.97 ns .. 16.35 ns)
0.992 R² (0.987 R² .. 1.000 R²)
mean 15.16 ns (15.07 ns .. 15.36 ns)
std dev 512.1 ps (353.9 ps .. 751.7 ps)
variance introduced by outliers: 15% (moderately inflated)
benchmarked CPS/1000
time 577.6 ns (563.9 ns .. 585.9 ns)
0.998 R² (0.997 R² .. 0.999 R²)
mean 583.4 ns (577.7 ns .. 590.3 ns)
std dev 21.44 ns (15.10 ns .. 29.04 ns)
variance introduced by outliers: 18% (moderately inflated)
benchmarked CPS/100000
time 56.28 μs (55.32 μs .. 57.26 μs)
0.998 R² (0.997 R² .. 0.999 R²)
mean 56.85 μs (56.44 μs .. 57.65 μs)
std dev 1.677 μs (1.298 μs .. 2.315 μs)
variance introduced by outliers: 13% (moderately inflated)
benchmarked Boxed Ref/10
time 57.18 ns (56.86 ns .. 57.48 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 56.75 ns (56.59 ns .. 56.96 ns)
std dev 670.3 ps (550.5 ps .. 821.1 ps)
benchmarked Boxed Ref/1000
time 4.472 μs (4.425 μs .. 4.506 μs)
0.999 R² (0.999 R² .. 1.000 R²)
mean 4.675 μs (4.613 μs .. 4.763 μs)
std dev 261.2 ns (187.5 ns .. 328.6 ns)
variance introduced by outliers: 34% (moderately inflated)
benchmarked Boxed Ref/100000
time 449.9 μs (447.2 μs .. 452.2 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 452.6 μs (451.9 μs .. 453.9 μs)
std dev 3.722 μs (2.991 μs .. 4.720 μs)
benchmarked Unboxed Ref/10
time 26.58 ns (25.55 ns .. 28.13 ns)
0.986 R² (0.976 R² .. 0.995 R²)
mean 26.91 ns (26.44 ns .. 27.57 ns)
std dev 1.860 ns (1.578 ns .. 2.179 ns)
variance introduced by outliers: 44% (moderately inflated)
benchmarked Unboxed Ref/1000
time 1.804 μs (1.789 μs .. 1.823 μs)
0.999 R² (0.998 R² .. 0.999 R²)
mean 1.871 μs (1.855 μs .. 1.888 μs)
std dev 60.56 ns (50.02 ns .. 70.59 ns)
variance introduced by outliers: 15% (moderately inflated)
benchmarked Unboxed Ref/100000
time 178.6 μs (176.6 μs .. 181.6 μs)
0.998 R² (0.997 R² .. 0.999 R²)
mean 184.2 μs (182.9 μs .. 186.0 μs)
std dev 5.591 μs (4.149 μs .. 8.359 μs)
variance introduced by outliers: 13% (moderately inflated)
module Main where
import Control.Monad.Trans.Writer.Ref
import qualified Control.Monad.Writer.CPS as CPS
import Control.Monad.ST
import Data.Foldable (for_)
import Data.Monoid
import Data.Semigroup
import Data.Mutable
import qualified Data.Vector.Generic.Mutable as M
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed as U
import GHC.Generics
import Gauge.Main
-------------------------------------------------------------------------------
instance Semigroup Int where
a <> b = a + b
stimes n a = fromIntegral n * a
instance Monoid Int where
mempty = 0
-------------------------------------------------------------------------------
testCPSWriter' :: Int -> CPS.Writer Int ()
testCPSWriter' n = for_ [1..n] $ \x -> tell x
testCPSWriter :: Int -> Int
testCPSWriter n = CPS.execWriter (testCPSWriter' n)
testBoxedRefWriter'
:: Int
-> WriterRefT (STRef ps) Int (ST ps) ()
testBoxedRefWriter' n = for_ [1..n] $ \x -> tell x
testBoxedRefWriter :: Int -> Int
testBoxedRefWriter n =
snd
$ runST
$ runWriterRefT (testBoxedRefWriter' n)
testUnboxedRefWriter'
:: Int
-> WriterRefT (URef ps) Int (ST ps) ()
testUnboxedRefWriter' n = for_ [1..n] $ \x -> tell x
testUnboxedRefWriter :: Int -> Int
testUnboxedRefWriter n =
snd
$ runST
$ runWriterRefT (testUnboxedRefWriter' n)
-------------------------------------------------------------------------------
main :: IO ()
main = defaultMain [
bgroup "CPS" [ bench "10" $ whnf testCPSWriter 10
, bench "1000" $ whnf testCPSWriter 1000
, bench "100000" $ whnf testCPSWriter 100000
]
, bgroup "Boxed Ref" [ bench "10" $ whnf testBoxedRefWriter 10
, bench "1000" $ whnf testBoxedRefWriter 1000
, bench "100000" $ whnf testBoxedRefWriter 100000
]
, bgroup "Unboxed Ref" [ bench "10" $ whnf testUnboxedRefWriter 10
, bench "1000" $ whnf testUnboxedRefWriter 1000
, bench "100000" $ whnf testUnboxedRefWriter 100000
]
]
name: writert-bench
version: 0.0.1
github: ""
license: MIT
author: ""
maintainer: "example@example.com"
copyright: ""
description: TBD
executables:
main:
main: Main.hs
source-dirs: executables
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- base >= 4.7 && < 5
- gauge
- monad-unlift-ref
- mutable-containers
- writer-cps-mtl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment