mirror of
https://github.com/danbulant/markdown-wasm
synced 2026-05-19 04:18:38 +00:00
update example
This commit is contained in:
parent
b407df075e
commit
cce8d5c948
2 changed files with 13 additions and 11 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<p>This is a paragraph</p>
|
||||
<h2><a id="another" class="anchor" aria-hidden="true" href="#another"></a>Another</h2>
|
||||
<p>This is a paragraph with style <em>italic</em> <em>italic</em> <b>bold</b> <b>bold</b></p>
|
||||
<p><img src="https://rsms.me/image.png" alt="image">
|
||||
<p><img src="https://rsms.me/raster/examples/image1.jpg" alt="image">
|
||||
<img src="https://rsms.me/image.png?without-alt" alt=""></p>
|
||||
<p><em>Hello <a href="https://rsms.me/">link</a> lol</em></p>
|
||||
<p>Hello <a href="https://rsms.me/"><em>link</em></a> lol "cat"</p>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
const RELEASE = process.argv.includes("-release")
|
||||
|
||||
const fs = require("fs")
|
||||
const md = RELEASE ? require("../build/release/md.js") : require("../build/debug/md.js")
|
||||
const md = require("../dist/markdown.node.js")
|
||||
|
||||
const source = fs.readFileSync(__dirname + "/example.md")
|
||||
const outbuf = md.parse(source, { asMemoryView: true })
|
||||
const outbuf = md.parse(source, { bytes: true })
|
||||
const outfile = __dirname + "/example.html"
|
||||
console.log("write", outfile)
|
||||
fs.writeFileSync(outfile, outbuf)
|
||||
|
|
@ -12,13 +10,17 @@ fs.writeFileSync(outfile, outbuf)
|
|||
console.log(fs.readFileSync(outfile, "utf8"))
|
||||
|
||||
// mini benchmark
|
||||
if (RELEASE) {
|
||||
console.log("benchmark start")
|
||||
if (process.argv.includes("-bench")) {
|
||||
console.log("benchmark start (sampling ~2s of data)")
|
||||
const timeStart = Date.now()
|
||||
const iterations = 10000
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
global["dont-optimize-away"] = md.parse(source, { asMemoryView: true })
|
||||
const N = 1000, T = 2000
|
||||
let ntotal = 0
|
||||
while (Date.now() - timeStart < 2000) {
|
||||
for (let i = 0; i < N; i++) {
|
||||
global["dont-optimize-away"] = md.parse(source, { bytes: true })
|
||||
}
|
||||
ntotal += N
|
||||
}
|
||||
const timeSpent = Date.now() - timeStart
|
||||
console.log(`benchmark end -- avg parse time: ${(timeSpent / iterations).toFixed(2)}ms`)
|
||||
console.log(`benchmark end -- avg parse time: ${((timeSpent / ntotal) * 1000).toFixed(1)}us`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue