Skip to content

Commit

Permalink
add some benchmarks specifically for file name
Browse files Browse the repository at this point in the history
  • Loading branch information
lehmacdj committed Mar 12, 2022
1 parent 50672f5 commit deb5672
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion commonmark/benchmark/benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ main = do
]
, bgroup "pathological"
(map toPathBench pathtests)
, bgroup "name impact"
(map (toNameImpactBench sample) nameImpactTests)
]

toPathBench :: (String, Int -> T.Text) -> Benchmark
Expand Down Expand Up @@ -88,11 +90,30 @@ pathtests =
("a" <> T.replicate num "<!A "))
]

toNameImpactBench :: Text -> (String, String) -> Benchmark
toNameImpactBench sample (testName, name) =
let benchArgs n = (show n, take (50 * n) (cycle name), sample)
in bgroup testName
(map (benchCommonmark' defaultSyntaxSpec . benchArgs)
[10, 20, 30, 40])

nameImpactTests :: [(String, String)]
nameImpactTests =
[ ("no special characters", "the quick brown fox jumped over the lazy dog")
, ("special characters", "\\-:-as;df-::%%-:\\;;;\\-:%%-:---:-sdf-:sa-\\;")
]

benchCommonmark :: SyntaxSpec Identity (Html ()) (Html ())
-> (String, Text)
-> Benchmark
benchCommonmark spec (name, contents) =
bench name $
benchCommonmark' spec (name, name, contents)

benchCommonmark' :: SyntaxSpec Identity (Html ()) (Html ())
-> (String, String, Text)
-> Benchmark
benchCommonmark' spec (testName, name, contents) =
bench testName $
nf (either (error . show) renderHtml
. runIdentity . parseCommonmarkWith spec . tokenize name)
contents
Expand Down

0 comments on commit deb5672

Please sign in to comment.