Skip to content

Commit

Permalink
Use strict annotations in Benchmark
Browse files Browse the repository at this point in the history
This prevents values from being evaluated within the benchmark.
  • Loading branch information
sebnow committed Oct 14, 2011
1 parent b56a4d1 commit e81bda5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Benchmark.hs
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.DeepSeq (NFData, rnf)
import Criterion.Main
Expand All @@ -17,19 +18,17 @@ ipv4str n = "192.168." ++ show (n `div` 255)
++ "."
++ show (n `mod` 255)

ipv4 :: IPv4
ipv4 = toAddress 3232235777

ipv6 :: IPv6
ipv6 = toAddress 42540766452641154071740215577757643572

ipv4subnet :: IPSubnet IPv4
ipv4subnet = IPSubnet ipv4 (toMask (8 :: Int))

ipv6subnet :: IPSubnet IPv6
ipv6subnet = IPSubnet ipv6 (toMask (56 :: Integer))

main = defaultMain
main =
let ipv4 :: IPv4
!ipv4 = toAddress 3232235777
ipv6 :: IPv6
!ipv6 = toAddress 42540766452641154071740215577757643572
ipv4subnet :: IPSubnet IPv4
!ipv4subnet = IPSubnet ipv4 (toMask (8 :: Int))
ipv6subnet :: IPSubnet IPv6
!ipv6subnet = IPSubnet ipv6 (toMask (56 :: Integer))
in defaultMain
[ bgroup "IPv4"
[ bench "readAddress" $ nf (readAddress :: String -> IPv4) "192.168.1.1"
, bench "showAddress" $ nf showAddress ipv4
Expand Down

0 comments on commit e81bda5

Please sign in to comment.