<commit_before>module Debug.Profile where

import Prelude
import Debug.Trace
import Control.Monad.Eff
import Control.Monad.Eff.Console
import Control.Monad.Eff.Unsafe

profileA :: forall m a. (Monad m) => String -> (Unit -> m a) -> m a
profileA msg f = do
  let t  = unsafePerformEff sampleTime
  a <- f unit
  let t' = unsafePerformEff sampleTime
  traceA $ msg <> " (" <> (show $ t' - t) <> "ms)"
  pure a

foreign import sampleTime :: forall eff. Eff eff Int<commit_msg>Add `profileParser`<commit_after>module Debug.Profile where

import Prelude
import Debug.Trace
import Control.Monad.Eff
import Control.Monad.Eff.Console
import Control.Monad.Eff.Unsafe
import Text.Parsing.Parser (PState(..), ParserT(..), unParserT) as P

profileA :: forall m a. (Monad m) => String -> (Unit -> m a) -> m a
profileA msg f = do
  let t  = unsafePerformEff sampleTime
  a <- f unit
  let t' = unsafePerformEff sampleTime
  traceA $ msg <> " (" <> (show $ t' - t) <> " ms)"
  pure a

profileParser :: forall s m a. (Monad m) => String -> P.ParserT s m a -> P.ParserT s m a
profileParser msg p = P.ParserT $ \s -> profileA msg \_ -> P.unParserT p s

foreign import sampleTime :: forall eff. Eff eff Int
{'fraction_non_alphanumeric': 0.12552653748946924, 'fraction_numerical': 0.0, 'mean_word_length': 3.3837638376383765, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, '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': '2935504', 'n_tokens_mistral': 426, 'n_tokens_neox': 414, 'n_words': 145}