-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.mjs
56 lines (45 loc) · 1.26 KB
/
index.mjs
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
import { compile as compileByMdxRs } from "../index.js";
import fs from "fs";
import { compile as compileByMdxJs } from "@mdx-js/mdx";
import Table from "cli-table";
import path from "path";
import { fileURLToPath } from "url";
const table = new Table({
head: ["Name", "Time Spend"],
});
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const examplePath = path.resolve(__dirname, "./fixtures/example.md");
const content = fs.readFileSync(examplePath, "utf-8");
async function benchMdxjs() {
await Promise.all(
new Array(1000).fill(0).map(async (_, index) => {
await compileByMdxJs(content);
})
);
}
async function benchMdxRs() {
await Promise.all(
new Array(1000).fill(0).map(async (_, index) => {
await compileByMdxRs({
value: content,
filepath: "",
development: true,
root: "",
});
})
);
}
async function bench() {
let mdxRsTime = 0;
let mdxJsTime = 0;
let start = Date.now();
await benchMdxjs();
mdxJsTime = Date.now() - start;
start = Date.now();
await benchMdxRs();
mdxRsTime = Date.now() - start;
table.push(["mdx-js", `${mdxJsTime.toLocaleString()}ms`]);
table.push(["mdx-rs", `${mdxRsTime.toLocaleString()}ms`]);
console.log(table.toString());
}
bench();