Skip to content

Commit 81f78bc

Browse files
committed
Update attoparsec test
1 parent 024ef23 commit 81f78bc

File tree

5 files changed

+117
-58
lines changed

5 files changed

+117
-58
lines changed

http/attoparsec/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.stack-work

http/attoparsec/http.cabal

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
-- Initial mp4.cabal generated by cabal init. For further documentation,
2-
-- see http://haskell.org/cabal/users-guide/
3-
4-
name: http
5-
version: 0.1.0.0
6-
-- synopsis:
7-
-- description:
8-
license: MIT
9-
license-file: LICENSE
10-
author: Geoffroy Couprie
11-
maintainer: [email protected]
12-
-- copyright:
13-
category: Testing
14-
build-type: Simple
15-
-- extra-source-files:
16-
cabal-version: >=1.10
1+
-- This file has been generated from package.yaml by hpack version 0.28.2.
2+
--
3+
-- see: https://github.com/sol/hpack
4+
--
5+
-- hash: 739ef94705a26ac053f2fb48d565940a91e43bd069a7667d63c35b0bb474cac2
176

7+
name: http
8+
version: 0.1.1.0
9+
category: Testing
10+
homepage: https://github.com/rust-bakery/parser_benchmarks/tree/master/http/attoparsec
11+
author: Geoffroy Couprie
12+
maintainer: [email protected]
13+
license: MIT
14+
license-file: LICENSE
15+
build-type: Simple
16+
cabal-version: >= 1.10
1817

1918
executable http
20-
main-is: Main.hs
21-
-- other-modules:
22-
-- other-extensions:
23-
build-depends: base >=4.7 && <4.12,
24-
attoparsec >=0.13 && <0.14,
25-
attoparsec-binary >=0.2 && <0.3,
26-
bytestring >=0.10 && <0.11,
27-
criterion >=1.1 && <1.5
28-
hs-source-dirs: src
29-
default-language: Haskell2010
30-
--ghc-options: -O2 -fllvm -pgmlo opt-3.4 -pgmlc llc-3.4
19+
main-is: Main.hs
20+
other-modules:
21+
Paths_http
22+
hs-source-dirs:
23+
src
24+
ghc-options: -Wall -O2 -fllvm
25+
build-depends:
26+
attoparsec
27+
, base >=4.7 && <5
28+
, bytestring
29+
, criterion
30+
default-language: Haskell2010

http/attoparsec/package.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: http
2+
version: 0.1.1.0
3+
homepage: https://github.com/rust-bakery/parser_benchmarks/tree/master/http/attoparsec
4+
license: MIT
5+
author: Geoffroy Couprie
6+
maintainer: [email protected]
7+
category: Testing
8+
9+
dependencies:
10+
- base >= 4.7 && < 5
11+
- attoparsec
12+
- bytestring
13+
- criterion
14+
15+
ghc-options: -Wall -O2 -fllvm
16+
# -pgmlo opt-3.4
17+
# -pgmlc llc-3.4
18+
19+
executables:
20+
http:
21+
source-dirs: src
22+
main: Main.hs

http/attoparsec/src/Main.hs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

3-
import Criterion.Main (bench, bgroup, defaultMain,
4-
env, nfIO, whnf, whnfIO)
5-
import qualified Data.Attoparsec.Binary as Bin
3+
import Criterion.Main (bench, bgroup, defaultMain, env, whnf)
64
import qualified Data.ByteString as B
7-
import qualified Data.ByteString.Char8 as C8
85

96
import Control.Applicative
107
import Data.Attoparsec.ByteString as P
118
import Data.Attoparsec.ByteString.Char8 (char8, endOfLine, isDigit_w8)
12-
import Data.Attoparsec.ByteString.Char8 (isEndOfLine,
13-
isHorizontalSpace)
9+
import Data.Attoparsec.ByteString.Char8 (isEndOfLine, isHorizontalSpace)
1410
import Data.ByteString (ByteString)
1511
import Data.Word (Word8)
1612

@@ -48,34 +44,23 @@ messageHeader = Header
4844
request :: Parser (Request, [Header])
4945
request = (,) <$> requestLine <*> many messageHeader <* endOfLine
5046

47+
allRequests :: Parser [(Request, [Header])]
5148
allRequests = many1 request
5249

53-
data Response = Response {
54-
responseVersion :: ByteString
55-
, responseCode :: ByteString
56-
, responseMsg :: ByteString
57-
} deriving (Eq, Ord, Show)
58-
59-
responseLine :: Parser Response
60-
responseLine = Response <$> (httpVersion <* char8 ' ')
61-
<*> (P.takeWhile isDigit_w8 <* char8 ' ')
62-
<*> (takeTill isEndOfLine <* endOfLine)
63-
64-
response :: Parser (Response, [Header])
65-
response = (,) <$> responseLine <*> many messageHeader <* endOfLine
66-
6750
smallFile :: FilePath
6851
smallFile = "../http-requests.txt"
52+
6953
biggerFile :: FilePath
7054
biggerFile = "../bigger.txt"
7155

56+
setupEnv :: IO (ByteString, ByteString)
7257
setupEnv = do
7358
small <- B.readFile smallFile
7459
bigger <- B.readFile biggerFile
7560
return (small, bigger)
7661

77-
criterion :: IO ()
78-
criterion = defaultMain
62+
main :: IO ()
63+
main = defaultMain
7964
[
8065
env setupEnv $ \ ~(small, bigger) ->
8166
bgroup "IO"
@@ -84,7 +69,3 @@ criterion = defaultMain
8469
, bench "bigger" $ whnf (P.parseOnly allRequests) bigger
8570
]
8671
]
87-
88-
main :: IO ()
89-
main = criterion
90-
--main = B.readFile biggerFile >>= print . P.parseOnly allRequests

http/attoparsec/stack.yaml

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,65 @@
1-
resolver: lts-11.1
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# https://docs.haskellstack.org/en/stable/yaml_configuration/
26

7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
# resolver: ghcjs-0.1.0_ghc-7.10.2
15+
#
16+
# The location of a snapshot can be provided as a file or url. Stack assumes
17+
# a snapshot provided as a file might change, whereas a url resource does not.
18+
#
19+
# resolver: ./custom-snapshot.yaml
20+
# resolver: https://example.com/snapshots/2018-01-01.yaml
21+
resolver: lts-13.9
22+
23+
# User packages to be built.
24+
# Various formats can be used as shown in the example below.
25+
#
26+
# packages:
27+
# - some-directory
28+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
29+
# - location:
30+
# git: https://github.com/commercialhaskell/stack.git
31+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
33+
# subdirs:
34+
# - auto-update
35+
# - wai
336
packages:
4-
- '.'
37+
- .
38+
# Dependency packages to be pulled from upstream that are not in the resolver
39+
# using the same syntax as the packages field.
40+
# (e.g., acme-missiles-0.3)
41+
# extra-deps: []
542

6-
extra-deps: []
43+
# Override default flag values for local packages and extra-deps
44+
# flags: {}
745

8-
flags: {}
46+
# Extra package databases containing global packages
47+
# extra-package-dbs: []
948

10-
extra-package-dbs: []
49+
# Control whether we use the GHC we find on the path
50+
# system-ghc: true
51+
#
52+
# Require a specific version of stack, using version ranges
53+
# require-stack-version: -any # Default
54+
# require-stack-version: ">=1.7"
55+
#
56+
# Override the architecture used by stack, especially useful on Windows
57+
# arch: i386
58+
# arch: x86_64
59+
#
60+
# Extra directories used by stack for building
61+
# extra-include-dirs: [/path/to/dir]
62+
# extra-lib-dirs: [/path/to/dir]
63+
#
64+
# Allow a newer minor version of GHC than the snapshot specifies
65+
# compiler-check: newer-minor

0 commit comments

Comments
 (0)