Skip to content

Commit

Permalink
uuid-types: add more benchmark metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
hvr committed Dec 18, 2016
1 parent 94aa296 commit 716d80a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions uuid-types/tests/BenchUUID.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import qualified Data.ByteString.Lazy.Internal as BL
import Criterion.Main
import Data.Maybe (fromJust)
import qualified Data.Set as Set
import qualified Data.HashSet as HashSet
import qualified Data.ByteString.Lazy as BL
import qualified Data.UUID.Types as U
import Foreign (alloca, peek, poke)
Expand All @@ -24,6 +25,9 @@ main = do
u1 <- randomIO
let s1 = U.toString u1
b1 = U.toByteString u1
a1 = U.toASCIIBytes u1
t1 = U.toText u1
(w1a,w1b,w1c,w1d) = U.toWords u1
nil2 = fromJust $
U.fromString "00000000-0000-0000-0000-000000000000"
u2a = fromJust $ U.fromString "169a5a43-c051-4a16-98f4-08447ddd5dc0"
Expand All @@ -43,15 +47,25 @@ main = do
bench "null nil" $ whnf U.null U.nil,
bench "null nil2" $ whnf U.null nil2,
bench "eq same" $ whnf (==u2a) u2b,
bench "eq differ" $ whnf (==u2a) u3
bench "eq differ" $ whnf (==u2a) u3,
bench "compare same" $ whnf (compare u2a) u2b,
bench "compare differ" $ whnf (compare u2a) u3
],
bgroup "conversion" [
bench "toString" $ nf U.toString u1,
bench "fromString" $ nf U.fromString s1,
bench "toByteString" $ nf U.toByteString u1,
bench "fromByteString" $ nf U.fromByteString b1
bench "fromByteString" $ nf U.fromByteString b1,
bench "toASCIIBytes" $ nf U.toASCIIBytes u1,
bench "fromASCIIBytes" $ nf U.fromASCIIBytes a1,
bench "toWords" $ nf U.toWords u1,
bench "fromWords" $ nf (U.fromWords w1a w1b w1c) w1d,
bench "toText" $ nf U.toText u1,
bench "fromText" $ nf U.fromText t1
],
bench "set making" $ nf Set.fromList uuids,

bench "Set making" $ nf Set.fromList uuids,
bench "HashSet making" $ nf HashSet.fromList uuids,

bgroup "storable" [
bench "peek" $ nfIO (peek uuidPtr),
Expand Down
3 changes: 2 additions & 1 deletion uuid-types/uuid-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ benchmark benchmark
containers >= 0.4 && < 0.6,
criterion >= 0.4 && < 1.2,
deepseq >= 1.1 && < 1.5,
random >= 1.0.1 && < 1.2
random >= 1.0.1 && < 1.2,
unordered-containers >= 0.2.7 && < 0.3

0 comments on commit 716d80a

Please sign in to comment.