mirror of
https://github.com/danbulant/markdown-wasm
synced 2026-06-24 17:22:03 +00:00
improve example benchmark
This commit is contained in:
parent
2938af6f0b
commit
571f5ceb09
1 changed files with 17 additions and 3 deletions
|
|
@ -18,18 +18,32 @@ console.log(fs.readFileSync(outfile, "utf8"))
|
||||||
|
|
||||||
// mini benchmark
|
// mini benchmark
|
||||||
if (process.argv.includes("-bench")) {
|
if (process.argv.includes("-bench")) {
|
||||||
console.log("benchmark start (sampling ~2s of data)")
|
benchmark("bytes", {
|
||||||
|
bytes: true,
|
||||||
|
})
|
||||||
|
benchmark("bytes + onCodeBlock", {
|
||||||
|
bytes: true,
|
||||||
|
onCodeBlock(lang, body) {
|
||||||
|
return null // causes the body to be HTML-escaped & included as is
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function benchmark(name, options) {
|
||||||
|
console.log(`benchmark start ${name} (sampling ~2s of data)`)
|
||||||
const timeStart = Date.now()
|
const timeStart = Date.now()
|
||||||
const N = 1000, T = 2000
|
const N = 1000, T = 2000
|
||||||
let ntotal = 0
|
let ntotal = 0
|
||||||
while (Date.now() - timeStart < 2000) {
|
while (Date.now() - timeStart < 2000) {
|
||||||
for (let i = 0; i < N; i++) {
|
for (let i = 0; i < N; i++) {
|
||||||
global["dont-optimize-away"] = md.parse(source, { bytes: true })
|
global["dont-optimize-away"] = md.parse(source, options)
|
||||||
}
|
}
|
||||||
ntotal += N
|
ntotal += N
|
||||||
}
|
}
|
||||||
const timeSpent = Date.now() - timeStart
|
const timeSpent = Date.now() - timeStart
|
||||||
console.log(`benchmark end -- avg parse time: ${((timeSpent / ntotal) * 1000).toFixed(1)}us`)
|
console.log(
|
||||||
|
`benchmark end ${name} -- avg parse time: ` +
|
||||||
|
`${((timeSpent / ntotal) * 1000).toFixed(1)}us`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_escape(str) {
|
function html_escape(str) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue