Turn tour-example into benchmark

This commit is contained in:
lyxia 2018-01-05 14:12:38 -05:00
parent 1b5b102a79
commit 1c7d6ef883
2 changed files with 24 additions and 0 deletions

View File

@ -37,3 +37,15 @@ executable tour-example
text,
generic-random
default-language: Haskell2010
executable tour-bench
main-is: tour.hs
ghc-options: -O2
ghc-options: -ddump-simpl -dsuppress-all -dno-suppress-module-prefixes
cpp-options: -DBENCHMODE
build-depends:
base,
QuickCheck,
text,
generic-random
default-language: Haskell2010

View File

@ -1,5 +1,6 @@
-- Just another toy example
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
@ -31,6 +32,8 @@ instance Arbitrary MyType where
-- , (4, ThreeThings <$> (Just <$> arbitrary) <*> arbitrary <*> arbitrary)
-- ]
main :: IO ()
#ifndef BENCHMODE
main = do
-- Print some examples
sample (arbitrary @MyType)
@ -39,6 +42,15 @@ main = do
quickCheck $ \case
ThreeThings Nothing _ _ -> False
_ -> True
#else
-- Quick and dirty benchmark
main = do
xs <- generate (replicateM 1000000 (arbitrary @MyType))
go xs
where
go [] = print ()
go (x : xs) = x `seq` go xs
#endif
-- Ew. Sorry.
instance Show a => Show (Bool -> a) where