<commit_before>{-# LANGUAGE ExistentialQuantification #-}

module Main (main) where

import Data.List (foldl')

import Control.DeepSeq (NFData(..))
import Criterion.Main (defaultMain, bench, bgroup, nf)
import Data.Set (Set)
import System.Random (mkStdGen)
import System.Random.Shuffle (shuffle')
import qualified Data.Set as Set

import Data.BitSet (BitSet)
import qualified Data.BitSet as BS

data B = forall a. NFData a => B a

instance NFData B where
    rnf (B b) = rnf b

main :: IO ()
main = do
    let bs1 = BS.fromList elems1
        bs2 = BS.fromList elems2
        s1  = Set.fromList elems1
        s2  = Set.fromList elems2
        r   = mkStdGen 42
        shuffledElems1 = shuffle' elems1 n r
        shuffledElems2 = shuffle' elems2 (n `div` 2) r
    return $ rnf [B bs1, B bs2, B s1, B s2, B shuffledElems1, B shuffledElems2]
    defaultMain
        [ bgroup "Set"
          [ bench "fromList" (nf Set.fromList shuffledElems1)
          , bench "toList" (nf Set.toList s1)
          , bench "singleton" (nf Set.singleton n)
          , bench "insert" (nf (insertS elems1) Set.empty)
          , bench "delete" (nf (deleteS elems1) s1)
          , bench "notMember" (nf (notMemberS shuffledElems1) s1)
          , bench "member" (nf (memberS shuffledElems1) s1)
          , bench "isSubsetOf" (nf (Set.isSubsetOf s2) s1)
          , bench "isProperSubsetOf" (nf (Set.isProperSubsetOf s2) s1)
          , bench "intersection" (nf (Set.intersection s2) s1)
          , bench "difference" (nf (Set.difference s2) s1)
          , bench "union" (nf (Set.union s2) s1)
          , bench "map" (nf (Set.map id) s1)
          , bench "filter" (nf (Set.filter $ const True) s1)
          ]

        , bgroup "BitSet"
          [ bench "fromList" (nf BS.fromList shuffledElems1)
          , bench "toList" (nf BS.toList bs1)
          , bench "singleton" (nf BS.singleton n)
          , bench "insert" (nf (insertBS elems1) BS.empty)
          , bench "delete" (nf (deleteBS elems1) bs1)
          , bench "notMember" (nf (notMemberBS shuffledElems1) bs1)
          , bench "member" (nf (memberBS shuffledElems1) bs1)
          , bench "isSubsetOf" (nf (BS.isSubsetOf bs2) bs1)
          , bench "isProperSubsetOf" (nf (BS.isProperSubsetOf bs2) bs1)
          , bench "intersection" (nf (BS.intersection bs2) bs1)
          , bench "difference" (nf (BS.difference bs2) bs1)
          , bench "union" (nf (BS.union bs2) bs1)
          , bench "map" (nf (BS.map id) bs1)
          , bench "filter" (nf (BS.filter $ const True) bs1)
          ]
        ]
  where
    n :: Int
    n = 128
<commit_msg>Fixed 'filter' benchmark: former example was too trivial<commit_after>{-# LANGUAGE ExistentialQuantification #-}

module Main (main) where

import Data.List (foldl')

import Control.DeepSeq (NFData(..))
import Criterion.Main (defaultMain, bench, bgroup, nf)
import Data.Set (Set)
import System.Random (mkStdGen)
import System.Random.Shuffle (shuffle')
import qualified Data.Set as Set

import Data.BitSet (BitSet)
import qualified Data.BitSet as BS

data B = forall a. NFData a => B a

instance NFData B where
    rnf (B b) = rnf b

main :: IO ()
main = do
    let bs1 = BS.fromList elems1
        bs2 = BS.fromList elems2
        s1  = Set.fromList elems1
        s2  = Set.fromList elems2
        r   = mkStdGen 42
        shuffledElems1 = shuffle' elems1 n r
        shuffledElems2 = shuffle' elems2 (n `div` 2) r
    return $ rnf [B bs1, B bs2, B s1, B s2, B shuffledElems1, B shuffledElems2]
    defaultMain
        [ bgroup "Set"
          [ bench "fromList" (nf Set.fromList shuffledElems1)
          , bench "toList" (nf Set.toList s1)
          , bench "singleton" (nf Set.singleton n)
          , bench "insert" (nf (insertS elems1) Set.empty)
          , bench "delete" (nf (deleteS elems1) s1)
          , bench "notMember" (nf (notMemberS shuffledElems1) s1)
          , bench "member" (nf (memberS shuffledElems1) s1)
          , bench "isSubsetOf" (nf (Set.isSubsetOf s2) s1)
          , bench "isProperSubsetOf" (nf (Set.isProperSubsetOf s2) s1)
          , bench "intersection" (nf (Set.intersection s2) s1)
          , bench "difference" (nf (Set.difference s2) s1)
          , bench "union" (nf (Set.union s2) s1)
          , bench "map" (nf (Set.map id) s1)
          , bench "filter" (nf (Set.filter odd) s1)
          ]

        , bgroup "BitSet"
          [ bench "fromList" (nf BS.fromList shuffledElems1)
          , bench "toList" (nf BS.toList bs1)
          , bench "singleton" (nf BS.singleton n)
          , bench "insert" (nf (insertBS elems1) BS.empty)
          , bench "delete" (nf (deleteBS elems1) bs1)
          , bench "notMember" (nf (notMemberBS shuffledElems1) bs1)
          , bench "member" (nf (memberBS shuffledElems1) bs1)
          , bench "isSubsetOf" (nf (BS.isSubsetOf bs2) bs1)
          , bench "isProperSubsetOf" (nf (BS.isProperSubsetOf bs2) bs1)
          , bench "intersection" (nf (BS.intersection bs2) bs1)
          , bench "difference" (nf (BS.difference bs2) bs1)
          , bench "union" (nf (BS.union bs2) bs1)
          , bench "map" (nf (BS.map id) bs1)
          , bench "filter" (nf (BS.filter odd) bs1)
          ]
        ]
  where
    n :: Int
    n = 128

{'fraction_non_alphanumeric': 0.1153184165232358, 'fraction_numerical': 0.025243832472748137, 'mean_word_length': 2.339719029374202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1324982', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1854, 'n_words': 561}