From deb56721792e1e83d7c5ce47dbb2cc6ee1a67fd8 Mon Sep 17 00:00:00 2001
From: Devin Lehmacher <lehmacdj@gmail.com>
Date: Sat, 12 Mar 2022 13:02:46 -0800
Subject: [PATCH] add some benchmarks specifically for file name

---
 commonmark/benchmark/benchmark.hs | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/commonmark/benchmark/benchmark.hs b/commonmark/benchmark/benchmark.hs
index 44c9441..183f0d5 100644
--- a/commonmark/benchmark/benchmark.hs
+++ b/commonmark/benchmark/benchmark.hs
@@ -19,6 +19,8 @@ main = do
       ]
     , bgroup "pathological"
       (map toPathBench pathtests)
+    , bgroup "name impact"
+      (map (toNameImpactBench sample) nameImpactTests)
     ]
 
 toPathBench :: (String, Int -> T.Text) -> Benchmark
@@ -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