@@ -1,20 +1,22 @@
11{-# LANGUAGE CPP #-}
22
33#if !(MIN_VERSION_bytestring(0,10,0))
4+{-# OPTIONS_GHC -fno-warn-orphans #-}
45-- Needed for NFData instance
5−import Control.DeepSeq
6+import Control.DeepSeq
67import qualified Data.ByteString.Lazy.Internal as BL
78#endif
8−import Criterion.Main
9−import Data.Maybe (fromJust)
10−import qualified Data.Set as Set
11−import qualified Data.HashSet as HashSet
12−import qualified Data.ByteString.Lazy as BL
13−import qualified Data.UUID.Types as U
14−import Foreign (alloca, peek, poke)
15−import System.Random
9+import Criterion.Main
10+import qualified Data.ByteString.Lazy as BL
11+import qualified Data.HashSet as HashSet
12+import Data.Maybe (fromJust)
13+import qualified Data.Set as Set
14+import qualified Data.UUID.Types as U
15+import Foreign (alloca, peek, poke)
16+import System.Random
1617
1718#if !(MIN_VERSION_bytestring(0,10,0))
19+-- orphan
1820instance NFData BL.ByteString where
1921 rnf BL.Empty = ()
2022 rnf (BL.Chunk _ ts) = rnf ts
@@ -22,56 +24,56 @@ instance NFData BL.ByteString where
2224
2325main :: IO ()
2426main = do
25− u1 <- randomIO
26− let s1 = U.toString u1
27− b1 = U.toByteString u1
28− a1 = U.toASCIIBytes u1
29− t1 = U.toText u1
30− (w1a,w1b,w1c,w1d) = U.toWords u1
31− nil2 = fromJust $
32− U.fromString "00000000-0000-0000-0000-000000000000"
33− u2a = fromJust $ U.fromString "169a5a43-c051-4a16-98f4-08447ddd5dc0"
34− u2b = fromJust $ U.fromByteString $
35− BL.pack [0x16, 0x9a, 0x5a, 0x43, 0xc0, 0x51, 0x4a, 0x16,
36− 0x98, 0xf4, 0x08, 0x44, 0x7d, 0xdd, 0x5d, 0xc0]
37− u3 = fromJust $ U.fromString "dea6f619-1038-438b-b4af-f1cdec1e6e23"
27+ u1 <- randomIO
28+ let s1 = U.toString u1
29+ b1 = U.toByteString u1
30+ a1 = U.toASCIIBytes u1
31+ t1 = U.toText u1
32+ (w1a,w1b,w1c,w1d) = U.toWords u1
33+ nil2 = fromJust $
34+ U.fromString "00000000-0000-0000-0000-000000000000"
35+ u2a = fromJust $ U.fromString "169a5a43-c051-4a16-98f4-08447ddd5dc0"
36+ u2b = fromJust $ U.fromByteString $
37+ BL.pack [0x16, 0x9a, 0x5a, 0x43, 0xc0, 0x51, 0x4a, 0x16,
38+ 0x98, 0xf4, 0x08, 0x44, 0x7d, 0xdd, 0x5d, 0xc0]
39+ u3 = fromJust $ U.fromString "dea6f619-1038-438b-b4af-f1cdec1e6e23"
3840
39− -- setup for Storable benchmark
40− alloca $ \ uuidPtr -> do
41+ -- setup for Storable benchmark
42+ alloca $ \ uuidPtr -> do
4143
42− poke uuidPtr u1
44+ poke uuidPtr u1
4345
44− defaultMain [
45− bgroup "testing" [
46− bench "null non-nil" $ whnf U.null u1,
47− bench "null nil" $ whnf U.null U.nil,
48− bench "null nil2" $ whnf U.null nil2,
49− bench "eq same" $ whnf (==u2a) u2b,
50− bench "eq differ" $ whnf (==u2a) u3,
51− bench "compare same" $ whnf (compare u2a) u2b,
52− bench "compare differ" $ whnf (compare u2a) u3
53− ],
54− bgroup "conversion" [
55− bench "toString" $ nf U.toString u1,
56− bench "fromString" $ nf U.fromString s1,
57− bench "toByteString" $ nf U.toByteString u1,
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
65− ],
46+ defaultMain [
47+ bgroup "testing" [
48+ bench "null non-nil" $ whnf U.null u1,
49+ bench "null nil" $ whnf U.null U.nil,
50+ bench "null nil2" $ whnf U.null nil2,
51+ bench "eq same" $ whnf (==u2a) u2b,
52+ bench "eq differ" $ whnf (==u2a) u3,
53+ bench "compare same" $ whnf (compare u2a) u2b,
54+ bench "compare differ" $ whnf (compare u2a) u3
55+ ],
56+ bgroup "conversion" [
57+ bench "toString" $ nf U.toString u1,
58+ bench "fromString" $ nf U.fromString s1,
59+ bench "toByteString" $ nf U.toByteString u1,
60+ bench "fromByteString" $ nf U.fromByteString b1,
61+ bench "toASCIIBytes" $ nf U.toASCIIBytes u1,
62+ bench "fromASCIIBytes" $ nf U.fromASCIIBytes a1,
63+ bench "toWords" $ nf U.toWords u1,
64+ bench "fromWords" $ nf (U.fromWords w1a w1b w1c) w1d,
65+ bench "toText" $ nf U.toText u1,
66+ bench "fromText" $ nf U.fromText t1
67+ ],
6668
67− bench "Set making" $ nf Set.fromList uuids,
68− bench "HashSet making" $ nf HashSet.fromList uuids,
69+ bench "Set making" $ nf Set.fromList uuids,
70+ bench "HashSet making" $ nf HashSet.fromList uuids,
6971
70− bgroup "storable" [
71− bench "peek" $ nfIO (peek uuidPtr),
72− bench "poke" $ whnfIO $ poke uuidPtr u1
73− ]
72+ bgroup "storable" [
73+ bench "peek" $ nfIO (peek uuidPtr),
74+ bench "poke" $ whnfIO $ poke uuidPtr u1
7475 ]
76+ ]
7577
7678-- 50 uuids, so tests can be repeatable
7779uuids :: [U.UUID]