Skip to content

Commit 665c428

Browse files
committed
Add benchmark for string decoding
1 parent 6059598 commit 665c428

3 files changed

Lines changed: 144 additions & 0 deletions

File tree

bench/Main.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import Gauge.Main (defaultMain,bgroup,bench,whnf)
66

77
import Twitter100 (encodedTwitter100,byteStringTwitter100)
8+
import Url100 (encodedUrl100,byteStringUrl100)
89

910
import qualified Data.Bytes as Bytes
1011
import qualified Data.Bytes.Builder as BLDR
@@ -33,6 +34,13 @@ main = do
3334
valueTwitter100
3435
]
3536
]
37+
, bgroup "url"
38+
[ bgroup "100"
39+
[ bench "decode" $ whnf
40+
(\b -> J.decode (Bytes.fromByteArray b))
41+
encodedUrl100
42+
]
43+
]
3644
]
3745
, bgroup "aeson"
3846
[ bgroup "twitter"
@@ -44,5 +52,10 @@ main = do
4452
aesonValueTwitter100
4553
]
4654
]
55+
, bgroup "url"
56+
[ bgroup "100"
57+
[ bench "decode" (whnf (Aeson.decodeStrict' @Aeson.Value) byteStringUrl100)
58+
]
59+
]
4760
]
4861
]

common/Url100.hs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE QuasiQuotes #-}
3+
module Url100
4+
( encodedUrl100
5+
, byteStringUrl100
6+
) where
7+
8+
import Data.ByteString (ByteString)
9+
import Data.ByteString.Short (ShortByteString,toShort)
10+
import Data.Primitive (ByteArray)
11+
import Data.Text.Encoding (encodeUtf8)
12+
import NeatInterpolation (text)
13+
14+
import qualified Data.Primitive as PM
15+
import qualified Data.ByteString.Short.Internal as BSS
16+
17+
shortByteStringToByteArray :: ShortByteString -> ByteArray
18+
shortByteStringToByteArray (BSS.SBS x) = PM.ByteArray x
19+
20+
encodedUrl100 :: ByteArray
21+
encodedUrl100 =
22+
shortByteStringToByteArray (toShort byteStringUrl100)
23+
24+
byteStringUrl100 :: ByteString
25+
byteStringUrl100 = encodeUtf8
26+
[text|
27+
[ "https://balance.example.com/aunt.htm"
28+
, "http://anger.example.com/"
29+
, "https://www.example.edu/basket/branch#boat"
30+
, "http://www.example.com/bag?bead=approval"
31+
, "https://example.com/bike.php"
32+
, "https://www.example.net/"
33+
, "https://www.example.com/"
34+
, "https://example.com/birds"
35+
, "https://aftermath.example.com/"
36+
, "http://badge.example.org/bee/brake"
37+
, "https://bedroom.example.com/"
38+
, "http://www.example.com/activity.aspx"
39+
, "http://example.net/book/anger.aspx?aunt=base&bone=amusement"
40+
, "http://example.net/art/apparatus.php"
41+
, "http://www.example.net/boat/brick.html"
42+
, "http://www.example.com/amount.aspx#bat"
43+
, "http://ants.example.net/blow/bubble"
44+
, "http://example.com/badge.php"
45+
, "http://www.example.com/afterthought.php"
46+
, "http://www.example.com/"
47+
, "https://bit.example.com/"
48+
, "https://adjustment.example.com/?bee=beginner"
49+
, "http://example.com/bed/ball.html"
50+
, "http://www.example.net/"
51+
, "https://example.com/bikes/actor.php"
52+
, "https://www.example.com/brick"
53+
, "http://example.com/"
54+
, "http://example.com/branch/brake.html?afterthought=bee"
55+
, "http://www.example.net/?bells=blood&art=back"
56+
, "https://www.example.com/"
57+
, "http://achiever.example.com/arch?bit=boat"
58+
, "https://example.net/?believe=amusement&bee=book"
59+
, "http://www.example.com/bell"
60+
, "http://www.example.com/brake/bath"
61+
, "http://example.edu/#bikes"
62+
, "https://example.com/badge/birthday"
63+
, "https://www.example.com/art/afterthought"
64+
, "http://www.example.com/boundary.php"
65+
, "https://www.example.com/art"
66+
, "https://www.example.org/basket"
67+
, "https://www.example.com/blade.html?attraction=basket"
68+
, "http://www.example.com/balance.php"
69+
, "https://bike.example.com/advertisement"
70+
, "https://bag.example.org/art/attack.php?base=birds&authority=act"
71+
, "https://example.com/basin.php"
72+
, "https://example.com/babies/beginner.htm"
73+
, "https://www.example.org/"
74+
, "http://bike.example.com/"
75+
, "https://www.example.com/"
76+
, "http://www.example.com/"
77+
, "https://example.com/"
78+
, "https://www.example.com/alarm/air?account=account"
79+
, "https://example.com/"
80+
, "https://example.net/#ants"
81+
, "http://www.example.com/adjustment/boot"
82+
, "http://example.org/branch.htm"
83+
, "https://www.example.net/battle?boundary=airplane"
84+
, "http://example.com/"
85+
, "https://example.net/?book=board#ball"
86+
, "http://aftermath.example.com/#boot"
87+
, "https://www.example.org/"
88+
, "http://example.com/"
89+
, "http://example.com/alarm.html"
90+
, "http://example.com/bait"
91+
, "http://example.org/berry.php#alarm"
92+
, "http://www.example.net/baby/addition"
93+
, "http://www.example.org/"
94+
, "http://www.example.org/"
95+
, "https://example.com/"
96+
, "https://example.com/branch/adjustment"
97+
, "https://www.example.net/airport.aspx"
98+
, "http://www.example.com/alarm"
99+
, "https://www.example.com/afternoon"
100+
, "https://example.org/?brick=airplane#appliance"
101+
, "http://example.com/#bell"
102+
, "http://arithmetic.example.net/activity/beginner"
103+
, "http://beds.example.com/"
104+
, "https://art.example.com/"
105+
, "https://www.example.com/"
106+
, "https://www.example.com/alarm.html?beds=bottle"
107+
, "http://www.example.com/bike/baseball.html"
108+
, "http://www.example.com/"
109+
, "https://example.com/?blade=base"
110+
, "https://example.com/"
111+
, "https://example.org/bubble/amusement"
112+
, "http://example.com/ball/basket?activity=boat&branch=books"
113+
, "http://www.example.org/"
114+
, "https://www.example.com/army"
115+
, "http://bubble.example.com/#basketball"
116+
, "https://example.com/"
117+
, "https://www.example.com/box/basketball.php"
118+
, "http://agreement.example.com/breath.html#bag"
119+
, "http://www.example.com/"
120+
, "https://www.example.com/"
121+
, "http://example.com/?act=addition&bee=action"
122+
, "https://www.example.com/back"
123+
, "https://www.example.org/?argument=boundary"
124+
, "http://example.org/"
125+
, "http://example.org/anger.htm"
126+
, "http://attack.example.org/"
127+
]
128+
|]
129+
130+

json-syntax.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ benchmark bench
9292
main-is: Main.hs
9393
other-modules:
9494
Twitter100
95+
Url100

0 commit comments

Comments
 (0)