From cce8d5c948300a4928c67b66af6e287937d7a170 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Fri, 16 Oct 2020 16:02:33 -0700 Subject: [PATCH] update example --- example/example.html | 2 +- example/example.js | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/example/example.html b/example/example.html index d1bbf32..eeeea9a 100644 --- a/example/example.html +++ b/example/example.html @@ -4,7 +4,7 @@

This is a paragraph

Another

This is a paragraph with style italic italic bold bold

-

image +

image

Hello link lol

Hello link lol "cat"

diff --git a/example/example.js b/example/example.js index cd84ad9..bbd795e 100644 --- a/example/example.js +++ b/example/example.js @@ -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`) }