forked from brecert/nevula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.ts
103 lines (88 loc) · 2.03 KB
/
bench.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// deno run --allow-write --allow-read --allow-hrtime ./bench.ts update-readme
import {
bench,
runBenchmarks,
} from "https://deno.land/std@0.90.0/testing/bench.ts";
import {
defaultColumns,
prettyBenchmarkDown,
prettyBenchmarkProgress,
prettyBenchmarkResult,
} from "https://deno.land/x/pretty_benching@v0.3.2/mod.ts";
import { Marked } from "https://deno.land/x/markdown@v2.0.0/mod.ts";
import { addTextSpans, parseMarkup } from "./markup.ts";
const RUNS = 2500;
const INITIAL_SAMPLE = `
> **Hello world!**
**__inside__ __inside again__**
\`\`code\`\`
** ~~not~~ a complete marker! __complete__
`.trim();
const SAMPLE = INITIAL_SAMPLE.repeat(7);
bench({
name: "nertivia markup",
runs: RUNS,
func(b): void {
b.start();
parseMarkup(SAMPLE);
b.stop();
},
});
bench({
name: "/x/markdown@v2.0.0 (based on an older version of Marked)",
runs: RUNS,
func(b): void {
b.start();
Marked.parse(SAMPLE);
b.stop();
},
});
bench({
name: "nertivia markup with inserted text spans",
runs: RUNS,
func(b): void {
b.start();
addTextSpans(parseMarkup(SAMPLE));
b.stop();
},
});
runBenchmarks(
{ silent: true },
prettyBenchmarkProgress({}),
)
.then(
prettyBenchmarkResult({
parts: {
extraMetrics: true,
},
}),
)
.then(
prettyBenchmarkDown(
(markdown) => {
if (Deno.args[0] === "update-readme") {
const readme = Deno.readTextFileSync("./README.md");
const modifiedReadme = readme.replace(
/(<!-- BENCHMARKS START -->)[^]+(<!-- BENCHMARKS END -->)/g,
`$1\n${markdown.trim()}\n$2`,
);
Deno.writeTextFileSync("./README.md", modifiedReadme);
}
},
{
groups: [
{
include: /.+/,
name: "Simple Markup",
description: "```md\n" + INITIAL_SAMPLE + "\n```",
columns: [
...defaultColumns(),
],
},
],
},
),
)
.catch((e: any) => {
console.error(e.stack);
});