Skip to content

Commit 716d80a

Browse files
committed
uuid-types: add more benchmark metrics
1 parent 94aa296 commit 716d80a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

uuid-types/tests/BenchUUID.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import qualified Data.ByteString.Lazy.Internal as BL
88
import Criterion.Main
99
import Data.Maybe (fromJust)
1010
import qualified Data.Set as Set
11+
import qualified Data.HashSet as HashSet
1112
import qualified Data.ByteString.Lazy as BL
1213
import qualified Data.UUID.Types as U
1314
import Foreign (alloca, peek, poke)
@@ -24,6 +25,9 @@ main = do
2425
u1 <- randomIO
2526
let s1 = U.toString u1
2627
b1 = U.toByteString u1
28+
a1 = U.toASCIIBytes u1
29+
t1 = U.toText u1
30+
(w1a,w1b,w1c,w1d) = U.toWords u1
2731
nil2 = fromJust $
2832
U.fromString "00000000-0000-0000-0000-000000000000"
2933
u2a = fromJust $ U.fromString "169a5a43-c051-4a16-98f4-08447ddd5dc0"
@@ -43,15 +47,25 @@ main = do
4347
bench "null nil" $ whnf U.null U.nil,
4448
bench "null nil2" $ whnf U.null nil2,
4549
bench "eq same" $ whnf (==u2a) u2b,
46-
bench "eq differ" $ whnf (==u2a) u3
50+
bench "eq differ" $ whnf (==u2a) u3,
51+
bench "compare same" $ whnf (compare u2a) u2b,
52+
bench "compare differ" $ whnf (compare u2a) u3
4753
],
4854
bgroup "conversion" [
4955
bench "toString" $ nf U.toString u1,
5056
bench "fromString" $ nf U.fromString s1,
5157
bench "toByteString" $ nf U.toByteString u1,
52-
bench "fromByteString" $ nf U.fromByteString b1
58+
bench "fromByteString" $ nf U.fromByteString b1,
59+
bench "toASCIIBytes" $ nf U.toASCIIBytes u1,
60+
bench "fromASCIIBytes" $ nf U.fromASCIIBytes a1,
61+
bench "toWords" $ nf U.toWords u1,
62+
bench "fromWords" $ nf (U.fromWords w1a w1b w1c) w1d,
63+
bench "toText" $ nf U.toText u1,
64+
bench "fromText" $ nf U.fromText t1
5365
],
54-
bench "set making" $ nf Set.fromList uuids,
66+
67+
bench "Set making" $ nf Set.fromList uuids,
68+
bench "HashSet making" $ nf HashSet.fromList uuids,
5569

5670
bgroup "storable" [
5771
bench "peek" $ nfIO (peek uuidPtr),

uuid-types/uuid-types.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ benchmark benchmark
7676
containers >= 0.4 && < 0.6,
7777
criterion >= 0.4 && < 1.2,
7878
deepseq >= 1.1 && < 1.5,
79-
random >= 1.0.1 && < 1.2
79+
random >= 1.0.1 && < 1.2,
80+
unordered-containers >= 0.2.7 && < 0.3

0 commit comments

Comments
 (0)