<commit_before>module Main ( main
            ) where

import System.Environment
import Network.Openflow.Misc

import Network.Openflow.Types
import Network.Openflow.Ethernet.Types
import Data.Word
import Data.Bits
import Data.Monoid
import qualified Data.Vector.Storable as V
import Control.Applicative
import Network.Openflow.StrictPut
import qualified Data.Binary.Put as BP 
import Data.Binary.Get
import Data.Binary.Builder as BB
import Data.List
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BSI
import qualified Data.ByteString.Lazy as BL
import Control.Monad

import Foreign.Storable
import Foreign.ForeignPtr

import Text.Printf
import Debug.Trace

import Test.QuickCheck
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Gen
import System.Random

testNew :: [Word16] -> Word32
testNew lst = 
    icsum16 0 (V.fromList lst)

bsFromW16 w16 = BP.runPut $ BP.putBuilder $ foldl accPutWord16be BB.empty w16
    where accPutWord16be acc w = acc `BB.append` (BB.putWord16be w)


testOld :: [Word16] -> Word32
testOld lst = 
    icsum16' 0 bs
    where bs = bsFromW16 lst

test :: [Word16] -> Bool
test a = (testNew a) == (testOld a)
{-
testNew lst = 
    (icsum16 0 . V.fromList) <$> lst

testOld lst = 
    (icsum16' 0 . BS.pack) <$> lst -}

genLengthDEF = 10000 :: Int

main = do
    args <- getArgs
    gen <- getStdGen
    if length args > 0
        then do
            putStrLn "Test old crc"
            sample $ testOld <$> vector genLengthDEF 
        else do
            putStrLn "Test new crc"
            sample $ testNew <$> vector genLengthDEF
<commit_msg>flow-crc: test adding criterion<commit_after>module Main ( main
            ) where

import System.Environment
import Network.Openflow.Misc

import Network.Openflow.Types
import Network.Openflow.Ethernet.Types
import Data.Word
import Data.Bits
import Data.Monoid
import qualified Data.Vector.Storable as V
import Control.Applicative
import Network.Openflow.StrictPut
import qualified Data.Binary.Put as BP 
import Data.Binary.Get
import Data.Binary.Builder as BB
import Data.List
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BSI
import qualified Data.ByteString.Lazy as BL
import Control.Monad

import Foreign.Storable
import Foreign.ForeignPtr

import Text.Printf
import Debug.Trace

import Test.QuickCheck
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Gen
import System.Random

bsFromW16 w16 = BP.runPut $ BP.putBuilder $ foldl accPutWord16be BB.empty w16
    where accPutWord16be acc w = acc `BB.append` (BB.putWord16be w)

test :: [Word16] -> Bool
test a = (testNew a) == (testOld a)
{-
testNew lst = 
    (icsum16 0 . V.fromList) <$> lst

testOld lst = 
    (icsum16' 0 . BS.pack) <$> lst -}

genLengthDEF = 10000 :: Int

main = do
    test <- arbitary

    defaultMain [ bgrup "csumNew" $ nf testNew (V.fromList arbitary)
                , bgrup "csumOld" $ nf testOld (bsfromW16 arbitary)
                ]
{'fraction_non_alphanumeric': 0.08198924731182795, 'fraction_numerical': 0.023185483870967742, 'mean_word_length': 3.3908554572271385, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182545', 'n_tokens_mistral': 1026, 'n_tokens_neox': 956, 'n_words': 297}