{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-} module Bench ( mark ) where import Deriv.StrMat (Str, regexing, match, loadFile) import Data.Function ((&)) import Gauge (Benchmark, bench, nf, env, bgroup) import Optics.Core ((^..), (.~), (%)) import Text.Regex.PCRE.Heavy (Regex, re) mark :: String -> String -> Benchmark mark tag file = env (loadFile file) $ \str -> bgroup tag [ bench "static search" $ nf (search [re|ipsum|]) str , bench "complex search" $ nf (search [re|l\w+m|]) str , bench "simple replace" $ nf (replace [re|ipsum|] "lorem") str , bench "complex replace" $ nf (replace [re|i\w*s\w*m|] "dolor") str ] search :: Regex -> Str -> [Str] search pat src = src ^.. regexing pat % match replace :: Regex -> Str -> Str -> Str replace pat repl src = src & regexing pat % match .~ repl