size: 1 KiB
| 1 | local djot = require("djot") |
| 2 | |
| 3 | local n = 500 |
| 4 | |
| 5 | local deeplynested = {} |
| 6 | for i = 1,n do |
| 7 | deeplynested[#deeplynested + 1] = string.rep(" ", i) .. "* a\n" |
| 8 | end |
| 9 | |
| 10 | local backticks = {} |
| 11 | for i = 1, 5 * n do |
| 12 | backticks[#backticks + 1] = "e" .. string.rep("`", i) |
| 13 | end |
| 14 | |
| 15 | local tests = { |
| 16 | ["nested strong emph"] = |
| 17 | string.rep("_a *a ", 65*n) .. "b" .. string.rep(" a* a_", 65*n), |
| 18 | ["many emph closers with no openers"] = |
| 19 | string.rep("a_ ", 65*n), |
| 20 | ["many emph openers with no closers"] = |
| 21 | string.rep("_a ", 65*n), |
| 22 | ["many link closers with no openers"] = |
| 23 | string.rep("a]", 65*n), |
| 24 | ["many link openers with no closers"] = |
| 25 | string.rep("[a", 65*n), |
| 26 | ["mismatched openers and closers"] = |
| 27 | string.rep("*a_ ", 50*n), |
| 28 | ["issue cmark#389"] = |
| 29 | string.rep("*a ", 20*n) .. string.rep("_a*_ ", 20*n), |
| 30 | ["openers and closers multiple of 3"] = |
| 31 | "a**b" .. string.rep("8* ", 50 * n), |
| 32 | ["link openers and emph closers"] = |
| 33 | string.rep("[ a_", 50 * n), |
| 34 | ["pattern [ (]( repeated"] = |
| 35 | string.rep("[ (](", 80 * n), |
| 36 | ["nested brackets"] = |
| 37 | string.rep("[", 50 * n) .. "a" .. string.rep("]", 50*n), |
| 38 | ["nested block quotes"] = |
| 39 | string.rep("> ", 50*n) .. "a", |
| 40 | ["deeply nested lists"] = |
| 41 | table.concat(deeplynested), |
| 42 | ["backticks"] = |
| 43 | table.concat(backticks), |
| 44 | ["unclosed links"] = |
| 45 | string.rep("[a](<b", 30 * n), |
| 46 | ["unclosed attributes"] = |
| 47 | string.rep("a{#id k=", 30 * n), |
| 48 | } |
| 49 | |
| 50 | for name,test in pairs(tests) do |
| 51 | io.stdout:write(string.format("%-40s ", name)) |
| 52 | io.stdout:flush() |
| 53 | local before = os.clock() |
| 54 | djot.parse(test) |
| 55 | local elapsed = os.clock() - before |
| 56 | local kb_per_second = math.floor((#test / 1000) / elapsed) |
| 57 | io.stdout:write(string.format("%6d KB/s\n", kb_per_second)) |
| 58 | end |