on master help sign in
Benchmark for Storable instance
commit4fb273b9d3ded414c2aeb6aa3a16adbf9521d87b authorAntoine Latter <aslatter@gmail.com> dateSat 19 Oct 2013, 17:55 (13 years ago) parent89b9013
1 file changed+12−1
tests/BenchUUID.hs+12−1
tests/BenchUUID.hs+12−1
@@ -16,6 +16,7 @@ import qualified Data.UUID as U
1616import qualified Data.UUID.V1 as U
1717import qualified Data.UUID.V3 as U3
1818import qualified Data.UUID.V5 as U5
19+import Foreign (alloca, peek, poke)
1920import System.Random
2021import System.Random.Mersenne.Pure64
2122
@@ -47,6 +48,11 @@ main = do
4748 writeIORef randomState state'
4849 return uuid
4950
51+ -- setup for Storable benchmark
52+ alloca $ \ uuidPtr -> do
53+
54+ poke uuidPtr u1
55+
5056 defaultMain [
5157 bgroup "testing" [
5258 bench "null non-nil" $ whnf U.null u1,
@@ -67,7 +73,12 @@ main = do
6773 bench "V3" $ nf (U3.generateNamed U3.namespaceURL) n1,
6874 bench "V5" $ nf (U5.generateNamed U5.namespaceURL) n1
6975 ],
70− bench "set making" $ nf Set.fromList uuids
76+ bench "set making" $ nf Set.fromList uuids,
77+
78+ bgroup "storable" [
79+ bench "peek" $ nfIO (peek uuidPtr),
80+ bench "poke" $ poke uuidPtr u1
81+ ]
7182 ]
7283
7384-- 50 uuids, so tests can be repeatable