Files

17 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Times one render() of one line: marker + run of n chars + tail. Args: shape variant kib.
import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
const [shape, variant, kib] = process.argv.slice(2);
const src = readFileSync(process.env.MDP, 'utf8');
const window = {}; runInNewContext(src, { window });
class N { constructor(t) { this.c = []; } appendChild(x) { this.c.push(x); return x; } setAttribute() {} set textContent(v) {} get lastChild() { return this.c.at(-1); } }
const doc = { createElement: t => new N(t), createTextNode: t => ({ t }), createDocumentFragment: () => new N('#f') };
const n = Number(kib) * 1024;
const tail = { u2028: '
', u2029: '
', letter: 'x' }[variant];
const line = { ITEM: '-' + ' '.repeat(n), ATX: '#' + ' '.repeat(n), FENCE: '`'.repeat(n) }[shape] + tail;
const meter = {};
const t0 = performance.now();
window.MosaicMarkdown.render(line, doc, meter);
const ms = performance.now() - t0;
console.log(`${shape} ${variant} ${kib}KiB len=${line.length} ms=${ms.toFixed(1)} work=${meter.work} budget=${meter.budget}`);