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