summaryrefslogtreecommitdiff
path: root/bench/Main.hs
blob: ecfefcea5e98a4e5ff2e14b9980145bcc81d2c48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# OPTIONS -fno-warn-orphans #-}
module Main (main) where

import Control.DeepSeq
import Criterion.Main
import Network

import Network.BitTorrent as BT
import Network.BitTorrent.Exchange.Protocol as BT
import Data.Bitfield as BT


instance NFData PortNumber where
  rnf = rnf . (fromIntegral :: PortNumber -> Int)

instance NFData BlockIx where
  rnf (BlockIx a b c) = a `deepseq` b `deepseq` rnf c

instance NFData Block where
  rnf (Block a b c) = a `deepseq` b `deepseq` rnf c

instance NFData Bitfield

instance NFData Message where
  rnf (Have i)     = rnf i
  rnf (Bitfield b) = rnf b
  rnf (Request  b) = rnf b
  rnf (Piece    b) = rnf b
  rnf (Cancel   b) = rnf b
  rnf (Port     i) = rnf i
  rnf _ = ()  -- other fields are forced by pattern matching
{-
encodeMessages :: [Message] -> ByteString
encodeMessages xs = runPut (mapM_ put xs)

decodeMessages :: ByteString -> Either String [Message]
decodeMessages = runGet (many get)
-}
main :: IO ()
main = defaultMain []