Skip to content

Instantly share code, notes, and snippets.

@japesinator
Created March 16, 2015 16:32
Show Gist options
  • Save japesinator/757c00d6d8613d6abafc to your computer and use it in GitHub Desktop.
Save japesinator/757c00d6d8613d6abafc to your computer and use it in GitHub Desktop.
Programming_Misc/Haskell/integral » cabal exec runhaskell Main.hs
benchmarking integral/mine
time 49.60 ns (48.52 ns .. 50.70 ns)
0.996 R² (0.994 R² .. 0.998 R²)
mean 50.25 ns (49.22 ns .. 51.44 ns)
std dev 3.635 ns (2.956 ns .. 4.986 ns)
variance introduced by outliers: 85% (severely inflated)
benchmarking integral/not mine
time 50.62 ns (49.77 ns .. 51.62 ns)
0.998 R² (0.997 R² .. 0.999 R²)
mean 50.80 ns (50.06 ns .. 51.50 ns)
std dev 2.398 ns (1.971 ns .. 2.999 ns)
variance introduced by outliers: 69% (severely inflated)
module Main where
import Criterion.Main
import qualified Data.ByteString.Lazy as DBSL
import qualified Data.ByteString.Lazy.Char8 as DBSLC
import qualified Text.Show.ByteString as TSBS
isIntegral :: Float -> Bool
isIntegral = DBSL.isSuffixOf (DBSLC.pack ".0") . TSBS.show
isIntegral' :: Float -> Bool
isIntegral' x = x == fromInteger (round x)
mapII :: [Float] -> [Bool]
mapII = map isIntegral
mapII' :: [Float] -> [Bool]
mapII' = map isIntegral'
lotsOfFloats :: [Float]
lotsOfFloats = map (/ 100) [1..10000]
main :: IO ()
main = defaultMain [
bgroup "integral" [ bench "mine" $ whnf mapII lotsOfFloats
, bench "not mine" $ whnf mapII' lotsOfFloats
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment