git.iko.soy/typeable/attoparsec
on master help sign in
Move number parsing benchmarks into their own module
e9a20b6Bryan O'Sullivan
attoparsec.cabal+2
@@ -97,6 +97,8 @@ benchmark benchmarks
97 type: exitcode-stdio-1.0
97 type: exitcode-stdio-1.0
98 hs-source-dirs: benchmarks, .
98 hs-source-dirs: benchmarks, .
99 main-is: Benchmarks.hs
99 main-is: Benchmarks.hs
100+ other-modules:
101+ Numbers
100
102
101 ghc-options: -O2 -Wall
103 ghc-options: -O2 -Wall
102
104
benchmarks/Benchmarks.hs+4−56
@@ -6,9 +6,9 @@ import Control.DeepSeq (NFData(rnf))
6import Criterion.Main (bench, bgroup, defaultMain, nf)
6import Criterion.Main (bench, bgroup, defaultMain, nf)
7import Data.Bits
7import Data.Bits
8import Data.Char (isAlpha)
8import Data.Char (isAlpha)
9−import Data.Scientific (Scientific(..))
10import Data.Word (Word32)
9import Data.Word (Word32)
11import Data.Word (Word8)
10import Data.Word (Word8)
11+import Numbers (numbers)
12import Text.Parsec.Text ()
12import Text.Parsec.Text ()
13import Text.Parsec.Text.Lazy ()
13import Text.Parsec.Text.Lazy ()
14import qualified Data.Attoparsec.ByteString as AB
14import qualified Data.Attoparsec.ByteString as AB
@@ -74,67 +74,15 @@ main = do
74 , bgroup "takeWhile" [
74 , bgroup "takeWhile" [
75 bench "isAlpha" $ nf (ABL.parse (AC.takeWhile isAlpha)) bl
75 bench "isAlpha" $ nf (ABL.parse (AC.takeWhile isAlpha)) bl
76 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_ascii)) bl
76 , bench "isAlpha_ascii" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_ascii)) bl
77+ , bench "isAlpha_iso8859_15" $
77− , bench "isAlpha_iso8859_15" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_iso8859_15)) bl
78+ nf (ABL.parse (AC.takeWhile AC.isAlpha_iso8859_15)) bl
78 ]
79 ]
79 , bench "word32LE" $ nf (AB.parse word32LE) b
80 , bench "word32LE" $ nf (AB.parse word32LE) b
80 , bgroup "scan" [
81 , bgroup "scan" [
81 bench "short" $ nf (AB.parse quotedString) (BC.pack "abcdefghijk\"")
82 bench "short" $ nf (AB.parse quotedString) (BC.pack "abcdefghijk\"")
82 , bench "long" $ nf (AB.parse quotedString) b
83 , bench "long" $ nf (AB.parse quotedString) b
83 ]
84 ]
84−
85− , let strN = "1234.56789"
86− strNePos = "1234.56789e3"
87− strNeNeg = "1234.56789e-3"
88− in
89− bgroup "numbers"
85+ , numbers
90− [ let !tN = T.pack strN
91− !tNePos = T.pack strNePos
92− !tNeNeg = T.pack strNeNeg
93− in bgroup "Text"
94− [
95− bgroup "no power"
96− [ bench "double" $ nf (AT.parseOnly AT.double) tN
97− , bench "number" $ nf (AT.parseOnly AT.number) tN
98− , bench "rational" $ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tN
99− , bench "scientific" $ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tN
100− ]
101− , bgroup "positive power"
102− [ bench "double" $ nf (AT.parseOnly AT.double) tNePos
103− , bench "number" $ nf (AT.parseOnly AT.number) tNePos
104− , bench "rational" $ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tNePos
105− , bench "scientific" $ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tNePos
106− ]
107− , bgroup "negative power"
108− [ bench "double" $ nf (AT.parseOnly AT.double) tNeNeg
109− , bench "number" $ nf (AT.parseOnly AT.number) tNeNeg
110− , bench "rational" $ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tNeNeg
111− , bench "scientific" $ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tNeNeg
112− ]
113− ]
114− , let !bN = BC.pack strN
115− !bNePos = BC.pack strNePos
116− !bNeNeg = BC.pack strNeNeg
117− in bgroup "ByteString"
118− [ bgroup "no power"
119− [ bench "double" $ nf (AC.parseOnly AC.double) bN
120− , bench "number" $ nf (AC.parseOnly AC.number) bN
121− , bench "rational" $ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bN
122− , bench "scientific" $ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bN
123− ]
124− , bgroup "positive power"
125− [ bench "double" $ nf (AC.parseOnly AC.double) bNePos
126− , bench "number" $ nf (AC.parseOnly AC.number) bNePos
127− , bench "rational" $ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bNePos
128− , bench "scientific" $ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bNePos
129− ]
130− , bgroup "negative power"
131− [ bench "double" $ nf (AC.parseOnly AC.double) bNeNeg
132− , bench "number" $ nf (AC.parseOnly AC.number) bNeNeg
133− , bench "rational" $ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bNeNeg
134− , bench "scientific" $ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bNeNeg
135− ]
136− ]
137− ]
138 ]
86 ]
139
87
140-- Benchmarks bind and (potential) bounds-check merging.
88-- Benchmarks bind and (potential) bounds-check merging.
benchmarks/Numbers.hsnew file+81
@@ -0,0 +1,81 @@
1+{-# LANGUAGE BangPatterns #-}
2+
3+module Numbers (numbers) where
4+
5+import Criterion.Main (bench, bgroup, nf)
6+import Criterion.Types (Benchmark)
7+import Data.Scientific (Scientific(..))
8+import Text.Parsec.Text ()
9+import Text.Parsec.Text.Lazy ()
10+import qualified Data.Attoparsec.ByteString.Char8 as AC
11+import qualified Data.Attoparsec.Text as AT
12+import qualified Data.ByteString.Char8 as BC
13+import qualified Data.Text as T
14+
15+strN, strNePos, strNeNeg :: String
16+strN = "1234.56789"
17+strNePos = "1234.56789e3"
18+strNeNeg = "1234.56789e-3"
19+
20+numbers :: Benchmark
21+numbers = bgroup "numbers" [
22+ let !tN = T.pack strN
23+ !tNePos = T.pack strNePos
24+ !tNeNeg = T.pack strNeNeg
25+ in bgroup "Text"
26+ [
27+ bgroup "no power"
28+ [ bench "double" $ nf (AT.parseOnly AT.double) tN
29+ , bench "number" $ nf (AT.parseOnly AT.number) tN
30+ , bench "rational" $
31+ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tN
32+ , bench "scientific" $
33+ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tN
34+ ]
35+ , bgroup "positive power"
36+ [ bench "double" $ nf (AT.parseOnly AT.double) tNePos
37+ , bench "number" $ nf (AT.parseOnly AT.number) tNePos
38+ , bench "rational" $
39+ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tNePos
40+ , bench "scientific" $
41+ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tNePos
42+ ]
43+ , bgroup "negative power"
44+ [ bench "double" $ nf (AT.parseOnly AT.double) tNeNeg
45+ , bench "number" $ nf (AT.parseOnly AT.number) tNeNeg
46+ , bench "rational" $
47+ nf (AT.parseOnly (AT.rational :: AT.Parser Rational)) tNeNeg
48+ , bench "scientific" $
49+ nf (AT.parseOnly (AT.rational :: AT.Parser Scientific)) tNeNeg
50+ ]
51+ ]
52+ , let !bN = BC.pack strN
53+ !bNePos = BC.pack strNePos
54+ !bNeNeg = BC.pack strNeNeg
55+ in bgroup "ByteString"
56+ [ bgroup "no power"
57+ [ bench "double" $ nf (AC.parseOnly AC.double) bN
58+ , bench "number" $ nf (AC.parseOnly AC.number) bN
59+ , bench "rational" $
60+ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bN
61+ , bench "scientific" $
62+ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bN
63+ ]
64+ , bgroup "positive power"
65+ [ bench "double" $ nf (AC.parseOnly AC.double) bNePos
66+ , bench "number" $ nf (AC.parseOnly AC.number) bNePos
67+ , bench "rational" $
68+ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bNePos
69+ , bench "scientific" $
70+ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bNePos
71+ ]
72+ , bgroup "negative power"
73+ [ bench "double" $ nf (AC.parseOnly AC.double) bNeNeg
74+ , bench "number" $ nf (AC.parseOnly AC.number) bNeNeg
75+ , bench "rational" $
76+ nf (AC.parseOnly (AC.rational :: AC.Parser Rational)) bNeNeg
77+ , bench "scientific" $
78+ nf (AC.parseOnly (AC.rational :: AC.Parser Scientific)) bNeNeg
79+ ]
80+ ]
81+ ]
benchmarks/attoparsec-benchmarks.cabal+3−1
@@ -8,8 +8,10 @@ build-type: Simple
8
8
9executable attoparsec-benchmarks
9executable attoparsec-benchmarks
10 main-is: Benchmarks.hs
10 main-is: Benchmarks.hs
11+ other-modules:
12+ Numbers
11 hs-source-dirs: .. .
13 hs-source-dirs: .. .
12− ghc-options: -O2
14+ ghc-options: -O2 -Wall
13 build-depends:
15 build-depends:
14 array,
16 array,
15 base == 4.*,
17 base == 4.*,