on master help sign in
turn off strictness, add timing demo
9514a10aslatter
Data/UUID/Internal.hs+19−13
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
1+{-# LANGUAGE DeriveDataTypeable, CPP #-}
2
2
3-- |
3-- |
4-- Module : Data.UUID
4-- Module : Data.UUID
@@ -42,17 +42,23 @@ import System.Random
42
42
43import Text.Printf
43import Text.Printf
44
44
45+#ifndef STRICT
46+#define SLOT(x) x
47+#else
48+#define SLOT(x) {-# UNPACK #-} !x
49+#endif
50+
45-- |The UUID type. A 'Random' instance is provided which produces
51-- |The UUID type. A 'Random' instance is provided which produces
46-- version 3 UUIDs as specified in RFC 4122. The 'Storable' and
52-- version 3 UUIDs as specified in RFC 4122. The 'Storable' and
47-- 'Binary' instances are compatable with RFC 4122. The 'Binary'
53-- 'Binary' instances are compatable with RFC 4122. The 'Binary'
48-- instance serializes to network byte order.
54-- instance serializes to network byte order.
49data UUID = UUID
55data UUID = UUID
50− {uuid_timeLow :: {-# UNPACK #-} !Word32
56+ {uuid_timeLow :: SLOT(Word32)
51− ,uuid_timeMid :: {-# UNPACK #-} !Word16
57+ ,uuid_timeMid :: SLOT(Word16)
52− ,uuid_timeHigh :: {-# UNPACK #-} !Word16 -- includes version number
58+ ,uuid_timeHigh :: SLOT(Word16) -- includes version number
53− ,uuid_clockSeqHi :: {-# UNPACK #-} !Word8 -- includes reserved field
59+ ,uuid_clockSeqHi :: SLOT(Word8) -- includes reserved field
54− ,uuid_clokcSeqLow :: {-# UNPACK #-} !Word8
60+ ,uuid_clokcSeqLow :: SLOT(Word8)
55− ,uuid_node :: {-# UNPACK #-} !Node
61+ ,uuid_node :: SLOT(Node)
56 } deriving (Eq, Ord, Typeable)
62 } deriving (Eq, Ord, Typeable)
57
63
58instance Random UUID where
64instance Random UUID where
@@ -81,12 +87,12 @@ reserved :: Word8
81reserved = bit 7
87reserved = bit 7
82
88
83data Node = Node
89data Node = Node
84− {-# UNPACK #-} !Word8
90+ SLOT(Word8)
85− {-# UNPACK #-} !Word8
91+ SLOT(Word8)
86− {-# UNPACK #-} !Word8
92+ SLOT(Word8)
87− {-# UNPACK #-} !Word8
93+ SLOT(Word8)
88− {-# UNPACK #-} !Word8
94+ SLOT(Word8)
89− {-# UNPACK #-} !Word8
95+ SLOT(Word8)
90 deriving (Eq, Ord, Typeable)
96 deriving (Eq, Ord, Typeable)
91
97
92instance Random Node where
98instance Random Node where
Demo.hsnew file+16
@@ -0,0 +1,16 @@
1+
2+-- timing demo
3+
4+import Data.UUID
5+import System.Random
6+
7+newUUID :: IO UUID
8+newUUID = randomIO
9+
10+count = 300000
11+
12+main = sequence_ $ replicate count $ do
13+ x <- newUUID
14+ y <- newUUID
15+ seq (x == y) $ return ()
16+