Skip to content

Instantly share code, notes, and snippets.

@llimllib
Created August 14, 2024 15:28
Show Gist options
  • Save llimllib/4b87fd4042359b4812350038562dba03 to your computer and use it in GitHub Desktop.
Save llimllib/4b87fd4042359b4812350038562dba03 to your computer and use it in GitHub Desktop.
// Save test.mjs in the root of the repository, and run it as `node test.mjs`
import {fromMarkdown} from 'mdast-util-from-markdown'
import {
gfmAutolinkLiteralFromMarkdown,
gfmAutolinkLiteralToMarkdown
} from './lib/index.js'
const hundredA = 'a'.repeat(100)
const fileWithBreaks = `${hundredA}\n`.repeat(800)
const fileWithoutBreaks = `${hundredA}`.repeat(800)
// On my computer: parsing a file with breaks: 32.809ms
console.time('parsing a file with breaks')
fromMarkdown(fileWithBreaks, {
extensions: [],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown()]
})
console.timeEnd('parsing a file with breaks')
// On my computer: parsing a file without breaks: 10.127s
console.time('parsing a file without breaks')
fromMarkdown(fileWithoutBreaks, {
extensions: [],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown()]
})
console.timeEnd('parsing a file without breaks')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment