summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-04 17:40:14 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-04 17:40:14 +0400
commit83f68e719708d679b4c347fb0f586501fba5d973 (patch)
treecd1a62880788f3f27b6a99fe48bf7c30d5985bf5
parent506d971c0f37179a680399df3db2faeaa36c0272 (diff)
+ Add benchmarks for bitfields.
-rw-r--r--bench/Main.hs (renamed from bench/serialization.hs)17
-rw-r--r--network-bittorrent.cabal4
2 files changed, 17 insertions, 4 deletions
diff --git a/bench/serialization.hs b/bench/Main.hs
index c6d14328..4ce7c818 100644
--- a/bench/serialization.hs
+++ b/bench/Main.hs
@@ -6,7 +6,7 @@ import Control.DeepSeq
6import Criterion.Main 6import Criterion.Main
7import Data.ByteString (ByteString) 7import Data.ByteString (ByteString)
8import Data.Serialize 8import Data.Serialize
9import Network.BitTorrent 9import Network.BitTorrent as BT
10 10
11 11
12instance NFData BlockIx where 12instance NFData BlockIx where
@@ -33,12 +33,25 @@ encodeMessages xs = runPut (mapM_ put xs)
33decodeMessages :: ByteString -> Either String [Message] 33decodeMessages :: ByteString -> Either String [Message]
34decodeMessages = runGet (many get) 34decodeMessages = runGet (many get)
35 35
36bitfieldDiff :: Int -> Bitfield
37bitfieldDiff n = BT.empty n `difference` BT.empty n
38
39bitfieldMin :: Int -> Maybe Int
40bitfieldMin n = findMin (BT.empty n)
41
42bitfieldMax :: Int -> Maybe Int
43bitfieldMax n = findMax (BT.empty n)
44
36main :: IO () 45main :: IO ()
37main = do 46main = do
38 let datas = replicate 100000 (Request (BlockIx 0 0 0)) 47 let datas = replicate 10000 (Request (BlockIx 0 0 0))
39 48
40 defaultMain 49 defaultMain
41 [ datas `deepseq` bench "message/encode" $ nf encodeMessages datas 50 [ datas `deepseq` bench "message/encode" $ nf encodeMessages datas
42 , let binary = encodeMessages datas in 51 , let binary = encodeMessages datas in
43 binary `deepseq` bench "message/decode" $ nf decodeMessages binary 52 binary `deepseq` bench "message/decode" $ nf decodeMessages binary
53
54 , bench "bitfield/difference" $ nf bitfieldDiff 1000000
55 , bench "bitfield/min" $ nf bitfieldMin 10000000
56 , bench "bitfield/max" $ nf bitfieldMax 10000000
44 ] \ No newline at end of file 57 ] \ No newline at end of file
diff --git a/network-bittorrent.cabal b/network-bittorrent.cabal
index 6d00410a..02074287 100644
--- a/network-bittorrent.cabal
+++ b/network-bittorrent.cabal
@@ -112,9 +112,9 @@ test-suite properties
112 112
113 113
114 114
115benchmark serialization 115benchmark benchmarks
116 type: exitcode-stdio-1.0 116 type: exitcode-stdio-1.0
117 main-is: serialization.hs 117 main-is: Main.hs
118 hs-source-dirs: bench 118 hs-source-dirs: bench
119 119
120 build-depends: base == 4.* 120 build-depends: base == 4.*