Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bench/unclosed-brackets.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

// Unclosed `[`×N used to make findClosingBracket re-scan the remainder for every
// opener (quadratic). After the per-parse memo, the first failed scan marks the
// tail and the rest is O(1).
const test = require("node:test");
const assert = require("node:assert");
const { loadMarkengineInRealm } = require("../tests/support/loadMarkengine.cjs");

const E = loadMarkengineInRealm();
const BUDGET_MS = 1000;

test(`[×50000 parses inside ${BUDGET_MS} ms`, () => {
const source = "[".repeat(50000);
const started = performance.now();
E.parse(source);
const took = Math.round(performance.now() - started);
assert.ok(took < BUDGET_MS, `[×50000 took ${took} ms`);
});

test(`"*a "×10000 still inside 3000 ms (linear after no-close memo)`, () => {
const source = `${"*a ".repeat(10000)}x`;
const started = performance.now();
E.parse(source);
const took = Math.round(performance.now() - started);
assert.ok(took < 3000, `*a ×10000 took ${took} ms`);
});
Loading
Loading