<commit_before>module Perf.Runner where

import Perf.Benchmark (..)
import Native.Runner

data Result = Running String (Element,[Time])
            | Single String [Time]
            | Report String [Result]

display : Result -> Element
display result = case result of
  Running name (element,times) -> asText name `above` element `above` (asText times)
  Single name times ->   asText name `above` (asText times)
  Report name results -> foldr (\acc base -> base `above` (display acc)) (asText name) results

run : Benchmark -> Signal Result
run bm =
  case bm of
    Logic name fs -> let totalFunctions = length fs
                     in lift (benchmarkComplete name totalFunctions)
                        (lift (\x -> (spacer 0 0, x)) (runLogic fs))
    View name fs ->
      let totalFunctions = length fs
      in lift (benchmarkComplete name totalFunctions) (runView fs)
    Group name bms -> lift (Report name) (combine (map run bms))
    {-| We need `run` to wait for each element in bms to complete
        before going on to the next benchmark
    -}


benchmarkComplete : String -> Int -> (Element, [Time]) -> Result
benchmarkComplete name totalFunctions (element, times) =
  if totalFunctions == (length times)
  then Single name times
  else Running name (element, times)

runLogic : [()->()] -> Signal [Time]
runLogic fs = Native.Runner.runLogic fs

runView : [() -> Element] -> Signal (Element,[Time])
runView fs = Native.Runner.runView fs


--showResults : Result -> Element<commit_msg>notes, name, and style changes<commit_after>module Perf.Runner where

import Perf.Benchmark (..)
import Native.Runner

data Result = Running String (Element,[Time])
            | Single String [Time]
            | Report String [Result]

display : Result -> Element
display result = case result of
    Running name (element,times) ->
                         asText name `above` element `above` (asText times)
    Single name times -> asText name `above` (asText times)
    Report name results ->
        foldr (\result baseElement -> baseElement `above` (display result))
            (asText name) results

run : Benchmark -> Signal Result
run bm = case bm of
    Logic name fs -> let totalFunctions = length fs
                     in lift (status name totalFunctions)
                        (lift (\x -> (spacer 0 0, x)) (runLogic fs))
    View name fs ->
      let totalFunctions = length fs
      in lift (status name totalFunctions) (runView fs)
    Group name bms -> lift (Report name) (combine (map run bms))
    {-| We need `run` to wait for each element in bms to complete
        before going on to the next benchmark
    -}

{-| Get the status of a benchmark. As it is lifted, it will change
    from a running test to a completed single benchmark.
    Groups of benchmarks are broken down to individual tests and the status
    is displayed from there

    Question: Do we need to pass a string in? So therefore, we would return
    functions String -> Result. This would get lifted, so we would get
    Signal (String -> Result). Does Elm have a way to apply a value to this?
-}
status : String -> Int -> (Element, [Time]) -> Result
status name totalFunctions (element, times) =
    if totalFunctions == (length times)
    then Single name times
    else Running name (element, times)

runLogic : [()->()] -> Signal [Time]
runLogic fs = Native.Runner.runLogic fs

runView : [() -> Element] -> Signal (Element,[Time])
runView fs = Native.Runner.runView fs
{'fraction_non_alphanumeric': 0.09732219982723869, 'fraction_numerical': 0.001151742009789807, 'mean_word_length': 2.7967213114754097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 40, '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': '1302576', 'n_tokens_mistral': 977, 'n_tokens_neox': 935, 'n_words': 419}