Something went wrong. Try again.
A parser and stringifier for the KDL Document Language bram.tngl.io/kdl
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104import {parseArgs} from "node:util";
import bench from "benchmark";
import * as self from "../src/index.js";import * as compat from "../src/v1-compat.js";
const {full} = parseArgs({ strict: true, allowPositionals: false, options: { full: { type: "boolean", default: false, short: "f", }, },}).values;
const suite = new bench.Suite();
const document = String.raw`node \{ child; "child"; ###"child"###;}
deeply { nested { node { but { like { really { deeply { nested { or { whatever; }; }; }; }; }; }; }; }; }
node \ with="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ #"no really,"#="a lot" \ "of" "children" 4.20;`;
const documentV1 = document.replace(/(\s)(#+")/g, "$1r$2");
// sanity check: assert document parsesself.parse(document);
if (full) { const v1 = await import("@bgotink/kdl-v1"); suite.add("v1 #parse", () => { v1.parse(documentV1); });}
suite.add("v1 compat #parse", () => { compat.parse(documentV1);});
suite.add("development #parse", () => { self.parse(document);});
if (full) { suite.add("development #parse {graphemeLocations: true}", () => { self.parse(document, {graphemeLocations: true}); });
suite.add("development #parse {storeLocations: true}", () => { self.parse(document, {storeLocations: true}); });}
try { const out = await import("../out/index.js"); suite.add("built #parse", () => { out.parse(document); });} catch { // ignore}
// add listenerssuite .on( "cycle", /** @param {bench.Event} event */ function (event) { console.log(String(event.target)); }, ) .on( "complete", /** @this {bench.Suite} */ function () { console.log("Fastest is " + this.filter("fastest").map("name")); }, ) .run();