1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main (main) where
-------------------------------------------------------------------------------
import Blaze.ByteString.Builder
import Control.DeepSeq
import Criterion.Main
import Data.String
import qualified Network.URI as NU
-------------------------------------------------------------------------------
import URI.ByteString
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
instance NFData Authority
instance NFData Host
instance NFData UserInfo
instance NFData SchemaError
instance NFData URIParseError
instance NFData Scheme
instance NFData Port
instance NFData Query
instance NFData (URIRef a) where
rnf (URI a b c d e) = rnf a `seq` rnf b `seq` rnf c `seq` rnf d `seq` rnf e
rnf (RelativeRef b c d e) = rnf b `seq` rnf c `seq` rnf d `seq` rnf e
-------------------------------------------------------------------------------
main :: IO ()
main = defaultMain
[
bgroup "parsing"
[
bench "Network.URI.parseURI" $ nf NU.parseURI exampleURIS
, bench "URI.ByteString.parseURI strict" $ nf (parseURI strictURIParserOptions) exampleURIS
, bench "URI.ByteString.parseURI lax" $ nf (parseURI laxURIParserOptions) exampleURIS
, bench "URI.ByteString.parseRelativeRef strict" $ nf (parseRelativeRef strictURIParserOptions) exampleRelativeRefS
, bench "URI.ByteString.parseRelativeRef lax" $ nf (parseRelativeRef laxURIParserOptions) exampleRelativeRefS
]
, bgroup "serializing"
[
bench "URI.ByteString.serializeURIRef on URI" $ nf (toLazyByteString . serializeURIRef) exampleURI
, bench "URI.ByteString.serializeURIRef on relative ref" $ nf (toLazyByteString . serializeURIRef) exampleRelativeRef
]
]
exampleURIS :: IsString s => s
exampleURIS = "http://google.com/example?params=youbetcha"
exampleRelativeRefS :: IsString s => s
exampleRelativeRefS = "/example?params=youbetcha#17u"
exampleURI :: URI
exampleURI = URI {
uriScheme = Scheme "http"
, uriAuthority = Just Authority {
authorityUserInfo = Nothing
, authorityHost = Host "google.com"
, authorityPort = Nothing
}
, uriPath = "/example"
, uriQuery = Query [("params", "youbetcha")]
, uriFragment = Nothing
}
exampleRelativeRef :: RelativeRef
exampleRelativeRef = RelativeRef {
rrAuthority = Just Authority {
authorityUserInfo = Nothing
, authorityHost = Host "google.com"
, authorityPort = Nothing
}
, rrPath = "/example"
, rrQuery = Query [("params", "youbetcha")]
, rrFragment = Nothing
}
|