diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-05-04 17:40:14 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-05-04 17:40:14 +0400 |
commit | 83f68e719708d679b4c347fb0f586501fba5d973 (patch) | |
tree | cd1a62880788f3f27b6a99fe48bf7c30d5985bf5 /bench | |
parent | 506d971c0f37179a680399df3db2faeaa36c0272 (diff) |
+ Add benchmarks for bitfields.
Diffstat (limited to 'bench')
-rw-r--r-- | bench/Main.hs (renamed from bench/serialization.hs) | 17 |
1 files changed, 15 insertions, 2 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 | |||
6 | import Criterion.Main | 6 | import Criterion.Main |
7 | import Data.ByteString (ByteString) | 7 | import Data.ByteString (ByteString) |
8 | import Data.Serialize | 8 | import Data.Serialize |
9 | import Network.BitTorrent | 9 | import Network.BitTorrent as BT |
10 | 10 | ||
11 | 11 | ||
12 | instance NFData BlockIx where | 12 | instance NFData BlockIx where |
@@ -33,12 +33,25 @@ encodeMessages xs = runPut (mapM_ put xs) | |||
33 | decodeMessages :: ByteString -> Either String [Message] | 33 | decodeMessages :: ByteString -> Either String [Message] |
34 | decodeMessages = runGet (many get) | 34 | decodeMessages = runGet (many get) |
35 | 35 | ||
36 | bitfieldDiff :: Int -> Bitfield | ||
37 | bitfieldDiff n = BT.empty n `difference` BT.empty n | ||
38 | |||
39 | bitfieldMin :: Int -> Maybe Int | ||
40 | bitfieldMin n = findMin (BT.empty n) | ||
41 | |||
42 | bitfieldMax :: Int -> Maybe Int | ||
43 | bitfieldMax n = findMax (BT.empty n) | ||
44 | |||
36 | main :: IO () | 45 | main :: IO () |
37 | main = do | 46 | main = 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 |