on master help sign in
turn off strictness, add timing demo
commit9514a10c4be81845290916414fd9f3f0e9814a38 authoraslatter <aslatter@gmail.com> dateFri 3 Oct 2008, 00:24 (18 years ago) parentdf4f69f
2 files changed+35−13
Data/UUID/Internal.hs+19−13 Demo.hs+16
Data/UUID/Internal.hs+19−13
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
1+{-# LANGUAGE DeriveDataTypeable, CPP #-}
22
33-- |
44-- Module : Data.UUID
@@ -42,17 +42,23 @@ import System.Random
4242
4343import Text.Printf
4444
45+#ifndef STRICT
46+#define SLOT(x) x
47+#else
48+#define SLOT(x) {-# UNPACK #-} !x
49+#endif
50+
4551-- |The UUID type. A 'Random' instance is provided which produces
4652-- version 3 UUIDs as specified in RFC 4122. The 'Storable' and
4753-- 'Binary' instances are compatable with RFC 4122. The 'Binary'
4854-- instance serializes to network byte order.
4955data UUID = UUID
50− {uuid_timeLow :: {-# UNPACK #-} !Word32
51− ,uuid_timeMid :: {-# UNPACK #-} !Word16
52− ,uuid_timeHigh :: {-# UNPACK #-} !Word16 -- includes version number
53− ,uuid_clockSeqHi :: {-# UNPACK #-} !Word8 -- includes reserved field
54− ,uuid_clokcSeqLow :: {-# UNPACK #-} !Word8
55− ,uuid_node :: {-# UNPACK #-} !Node
56+ {uuid_timeLow :: SLOT(Word32)
57+ ,uuid_timeMid :: SLOT(Word16)
58+ ,uuid_timeHigh :: SLOT(Word16) -- includes version number
59+ ,uuid_clockSeqHi :: SLOT(Word8) -- includes reserved field
60+ ,uuid_clokcSeqLow :: SLOT(Word8)
61+ ,uuid_node :: SLOT(Node)
5662 } deriving (Eq, Ord, Typeable)
5763
5864instance Random UUID where
@@ -81,12 +87,12 @@ reserved :: Word8
8187reserved = bit 7
8288
8389data Node = Node
84− {-# UNPACK #-} !Word8
85− {-# UNPACK #-} !Word8
86− {-# UNPACK #-} !Word8
87− {-# UNPACK #-} !Word8
88− {-# UNPACK #-} !Word8
89− {-# UNPACK #-} !Word8
90+ SLOT(Word8)
91+ SLOT(Word8)
92+ SLOT(Word8)
93+ SLOT(Word8)
94+ SLOT(Word8)
95+ SLOT(Word8)
9096 deriving (Eq, Ord, Typeable)
9197
9298instance 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+