From 86998c32ce4095b9f6dd9f83cd301c51d5818b3a Mon Sep 17 00:00:00 2001 From: Index Int Date: Tue, 12 May 2015 22:44:27 +0300 Subject: [PATCH 1/3] Basic benchmark for Turtle.Pattern --- bench/Main.hs | 24 ++++++++++++++++++++++++ turtle.cabal | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 bench/Main.hs diff --git a/bench/Main.hs b/bench/Main.hs new file mode 100644 index 0000000..a096c2b --- /dev/null +++ b/bench/Main.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main where + +import qualified Data.Text as Text +import Criterion.Main +import Turtle + +main :: IO () +main = defaultMain + [ bgroup "Pattern" + [ let cats = Text.replicate 1000 "cat" + furniture = Text.replicate 5 " " + in bgroup "Cat Lady's House" + [ bench "Basic" + $ nf (match (many "cat")) cats + , bench "Letters" + $ nf (match (many (mconcat ["c", "a", "t"]))) cats + , bench "Spaces" + $ nf (match (many "cat" <* spaces)) (cats <> furniture) + , bench "Prefix" + $ nf (match (prefix (many "cat"))) (cats <> furniture) + ] + ] + ] diff --git a/turtle.cabal b/turtle.cabal index 02d1a17..98ad429 100644 --- a/turtle.cabal +++ b/turtle.cabal @@ -82,3 +82,15 @@ test-suite tests Build-Depends: base >= 4 && < 5 , doctest >= 0.9.12 && < 0.10 + +benchmark bench + Type: exitcode-stdio-1.0 + HS-Source-Dirs: bench + Main-Is: Main.hs + GHC-Options: -O2 -Wall -threaded + Default-Language: Haskell2010 + Build-Depends: + base >= 4 && < 5 , + criterion >= 1.1.0.0 && < 2 , + text < 1.3, + turtle From dc35a336d5e10fa8683b8eda589a7e324ba202e3 Mon Sep 17 00:00:00 2001 From: Index Int Date: Tue, 12 May 2015 23:46:02 +0300 Subject: [PATCH 2/3] Benchmark the `bounded` combinator --- bench/Main.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bench/Main.hs b/bench/Main.hs index a096c2b..d996b08 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -5,6 +5,11 @@ import qualified Data.Text as Text import Criterion.Main import Turtle +boundedNaive :: Int -> Int -> Pattern a -> Pattern [a] +boundedNaive m n p = do + x <- choice (map pure [m..n]) + count x p + main :: IO () main = defaultMain [ bgroup "Pattern" @@ -20,5 +25,16 @@ main = defaultMain , bench "Prefix" $ nf (match (prefix (many "cat"))) (cats <> furniture) ] + , let hearts n = Text.replicate n "heart" + in bgroup "Love Knows No Bounds" + [ bench "500-700:650 Naive" + $ nf (match (boundedNaive 500 700 "heart")) (hearts 650) + , bench "500-700:650" + $ nf (match (bounded 500 700 "heart")) (hearts 650) + , bench "5000-7000:6500 Naive" + $ nf (match (boundedNaive 5000 7000 "heart")) (hearts 6500) + , bench "5000-7000:6500" + $ nf (match (bounded 5000 7000 "heart")) (hearts 6500) + ] ] ] From 343f9815237f0ef5b55353f0232a51455fe7941c Mon Sep 17 00:00:00 2001 From: Index Int Date: Thu, 14 May 2015 04:59:05 +0300 Subject: [PATCH 3/3] Add .gitignore for build artifacts --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fb4ab9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist +.cabal-sandbox +cabal.sandbox.config