-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbenchmark.js
50 lines (43 loc) · 1.08 KB
/
benchmark.js
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
import {promises as fs} from 'node:fs'
import {transformSync as babel} from '@babel/core'
import marky from 'marky'
import gfm from 'remark-gfm'
import {sync as mdx1} from 'mdx1'
import {sync as mdx2} from 'mdx2'
import {compileSync as xdm} from '../index.js'
main()
async function main() {
/** @type {string} */
let doc
try {
doc = String(await fs.readFile('giant.mdx'))
} catch {
console.warn(
'Cannot read `giant.mdx`: please place a large file in the root of `xdm`'
)
return
}
run('@mdx-js/mdx 1', () => {
babel(mdx1(doc), {
cloneInputAst: false,
compact: true,
configFile: false,
plugins: ['@babel/plugin-transform-react-jsx']
})
})
run('@mdx-js/mdx 2', () => {
babel(mdx2(doc), {
cloneInputAst: false,
compact: true,
configFile: false,
plugins: ['@babel/plugin-transform-react-jsx']
})
})
run('xdm', () => xdm(doc, {remarkPlugins: [gfm]}))
}
function run(label, fn) {
marky.mark(label)
fn()
const entry = marky.stop(label)
console.log('%s: %ims', entry.name, entry.duration)
}