mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-07-18 13:55:46 +00:00
Compare commits
6 Commits
302f129522
...
c6f8b6ad90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6f8b6ad90 | ||
|
|
b552fc6f93 | ||
|
|
d5e4ee5f44 | ||
|
|
6c0f3f8e8c | ||
|
|
3531ba9742 | ||
| d881df7814 |
1
README
1
README
@@ -9,6 +9,7 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
|
|||||||
The following models are included in the benchmark run.
|
The following models are included in the benchmark run.
|
||||||
|
|
||||||
<!-- MODELS_START -->
|
<!-- MODELS_START -->
|
||||||
|
moonshotai/kimi-k3 EFF:medium
|
||||||
openai/gpt-5.6-luna EFF:high
|
openai/gpt-5.6-luna EFF:high
|
||||||
x-ai/grok-4.5
|
x-ai/grok-4.5
|
||||||
anthropic/claude-sonnet-5 EFF:high
|
anthropic/claude-sonnet-5 EFF:high
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
const SCRYPT_URL = "https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm";
|
||||||
|
|
||||||
|
async function hashPassword(password, salt) {
|
||||||
|
const { scrypt } = await import(SCRYPT_URL);
|
||||||
|
const enc = new TextEncoder();
|
||||||
|
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
|
||||||
|
return Array.from(hash, b => b.toString(16).padStart(2, "0")).join("");
|
||||||
|
}
|
||||||
|
export default hashPassword;
|
||||||
|
// Generation time: 36.726s
|
||||||
|
// Result: PASS
|
||||||
13
tests/11_geospatial/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
13
tests/11_geospatial/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
async function analyzeGPS(readings, boundary) {
|
||||||
|
if (!Array.isArray(readings) || readings.length < 2) return 0;
|
||||||
|
const m = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
|
||||||
|
const { booleanPointInPolygon: inside, lineString, length } = m.default ?? m;
|
||||||
|
const coords = readings
|
||||||
|
.filter(({ loc }) => loc && inside(loc, boundary, { ignoreBoundary: true }))
|
||||||
|
.sort((a, b) => a.ts - b.ts)
|
||||||
|
.map(({ loc }) => loc);
|
||||||
|
return coords.length < 2 ? 0 : +length(lineString(coords), { units: 'kilometers' }).toFixed(2);
|
||||||
|
}
|
||||||
|
export default analyzeGPS;
|
||||||
|
// Generation time: 75.533s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
const [{ parse }, m, { default: table }] = await Promise.all([
|
||||||
|
import('https://esm.sh/smol-toml@1'),
|
||||||
|
import('https://esm.sh/mnemonist@0.39'),
|
||||||
|
import('https://esm.sh/text-table@0.2')
|
||||||
|
]);
|
||||||
|
const { Heap } = m.default ?? m;
|
||||||
|
|
||||||
|
const { edges = [] } = parse(toml);
|
||||||
|
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||||
|
const parent = new Map(), rank = new Map();
|
||||||
|
|
||||||
|
const find = x => {
|
||||||
|
const p = parent.get(x);
|
||||||
|
return p === x ? x : (parent.set(x, find(p)), parent.get(x));
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const e of edges) {
|
||||||
|
heap.push(e);
|
||||||
|
for (const v of [e.from, e.to])
|
||||||
|
if (!parent.has(v)) (parent.set(v, v), rank.set(v, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = [['From', 'To', 'Weight']];
|
||||||
|
let totalWeight = 0, need = parent.size - 1;
|
||||||
|
|
||||||
|
while (need-- > 0 && heap.size) {
|
||||||
|
const { from, to, weight } = heap.pop();
|
||||||
|
const a = find(from), b = find(to);
|
||||||
|
if (a === b) continue;
|
||||||
|
if (rank.get(a) < rank.get(b)) parent.set(a, b);
|
||||||
|
else {
|
||||||
|
parent.set(b, a);
|
||||||
|
if (rank.get(a) === rank.get(b)) rank.set(a, rank.get(a) + 1);
|
||||||
|
}
|
||||||
|
rows.push([from, to, String(weight)]);
|
||||||
|
totalWeight += weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { table: table(rows), totalWeight };
|
||||||
|
}
|
||||||
|
export default computeMST;
|
||||||
|
// Generation time: 107.250s
|
||||||
|
// Result: FAIL
|
||||||
29
tests/1_dijkstra/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
29
tests/1_dijkstra/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
let pqLib;
|
||||||
|
|
||||||
|
const loadPriorityQueue = () =>
|
||||||
|
pqLib ??= import('https://esm.sh/js-priority-queue@0.1.5')
|
||||||
|
.catch(() => import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm'));
|
||||||
|
|
||||||
|
async function findShortestPath(graph, start, end) {
|
||||||
|
const { default: PriorityQueue } = await loadPriorityQueue();
|
||||||
|
const dist = new Map([[start, 0]]);
|
||||||
|
const heap = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||||
|
heap.queue([start, 0]);
|
||||||
|
|
||||||
|
while (heap.length) {
|
||||||
|
const [node, d] = heap.dequeue();
|
||||||
|
if (node === end) return d;
|
||||||
|
if (d > (dist.get(node) ?? Infinity)) continue;
|
||||||
|
for (const [next, w] of Object.entries(graph[node] ?? {})) {
|
||||||
|
const nd = d + w;
|
||||||
|
if (nd < (dist.get(next) ?? Infinity)) {
|
||||||
|
dist.set(next, nd);
|
||||||
|
heap.queue([next, nd]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Infinity;
|
||||||
|
}
|
||||||
|
export default findShortestPath;
|
||||||
|
// Generation time: 122.554s
|
||||||
|
// Result: PASS
|
||||||
31
tests/2_convex_hull/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
31
tests/2_convex_hull/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
async function findConvexHull(points) {
|
||||||
|
if (!Array.isArray(points) || points.some(p => !p || !Number.isFinite(p.x) || !Number.isFinite(p.y))) {
|
||||||
|
throw new TypeError('findConvexHull expects an array of finite {x, y} points');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
|
||||||
|
const ps = uniqWith(
|
||||||
|
sortBy(points.map(({ x, y }) => ({ x, y })), ['x', 'y']),
|
||||||
|
(a, b) => a.x === b.x && a.y === b.y
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ps.length < 3) return ps;
|
||||||
|
|
||||||
|
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||||
|
const half = q => {
|
||||||
|
const h = [];
|
||||||
|
for (const p of q) {
|
||||||
|
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||||
|
h.push(p);
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
|
||||||
|
const lo = half(ps);
|
||||||
|
const hi = half([...ps].reverse());
|
||||||
|
|
||||||
|
return [...lo.slice(0, -1), ...hi.slice(0, -1)];
|
||||||
|
}
|
||||||
|
export default findConvexHull;
|
||||||
|
// Generation time: 96.201s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
const CDN = [
|
||||||
|
'https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm',
|
||||||
|
'https://cdn.jsdelivr.net/npm/mathjs@13/+esm',
|
||||||
|
'https://cdn.jsdelivr.net/npm/ndarray@1.0.19/+esm',
|
||||||
|
'https://cdn.jsdelivr.net/npm/ndarray-fft@1.0.3/+esm',
|
||||||
|
'https://cdn.jsdelivr.net/npm/dompurify@3.1.6/+esm'
|
||||||
|
];
|
||||||
|
|
||||||
|
let libs;
|
||||||
|
const loadLibs = () => (libs ??= Promise.all(CDN.map((u) => import(u))));
|
||||||
|
const pick = (m, k) => (m?.[k] !== undefined ? m : m?.default ?? m);
|
||||||
|
|
||||||
|
async function analyzeSignal(yamlString) {
|
||||||
|
if (typeof yamlString !== 'string') throw new TypeError('analyzeSignal expects a YAML string');
|
||||||
|
|
||||||
|
const [yamlM, mathM, ndM, fftM, dpM] = await loadLibs();
|
||||||
|
const { load } = pick(yamlM, 'load');
|
||||||
|
const math = pick(mathM, 'sin');
|
||||||
|
const ndarray = ndM?.default ?? ndM;
|
||||||
|
const fft = fftM?.default ?? fftM;
|
||||||
|
const DOMPurify = dpM?.default ?? dpM;
|
||||||
|
|
||||||
|
const { sampleRate, duration, components = [] } = load(yamlString);
|
||||||
|
const N = sampleRate * duration;
|
||||||
|
if (!Number.isInteger(N) || N < 2 || (N & (N - 1))) {
|
||||||
|
throw new RangeError(`sampleRate * duration must be a power of two >= 2 (got ${N})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new Float64Array(N);
|
||||||
|
for (let i = 0; i < N; i++) {
|
||||||
|
const t = i / sampleRate;
|
||||||
|
data[i] = components.reduce((s, { frequency: f, amplitude: a }) => s + a * math.sin(2 * math.pi * f * t), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const real = ndarray(data, [N]);
|
||||||
|
const imag = ndarray(new Float64Array(N), [N]);
|
||||||
|
fft(1, real, imag);
|
||||||
|
|
||||||
|
const half = N >> 1;
|
||||||
|
const peaks = Array.from({ length: half + 1 }, (_, k) => ({
|
||||||
|
k,
|
||||||
|
m: math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half
|
||||||
|
}))
|
||||||
|
.filter(({ m }) => m > 0.1)
|
||||||
|
.sort((a, b) => b.m - a.m)
|
||||||
|
.map(({ k, m }) => ({ frequencyHz: Math.round(k * sampleRate / N), magnitude: +m.toFixed(2) }));
|
||||||
|
|
||||||
|
const rows = peaks.map(({ frequencyHz, magnitude }) => `<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`).join('');
|
||||||
|
const html = DOMPurify.sanitize(`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`);
|
||||||
|
|
||||||
|
return { peaks, html, signalLength: N };
|
||||||
|
}
|
||||||
|
|
||||||
|
globalThis.analyzeSignal = analyzeSignal;
|
||||||
|
export default analyzeSignal;
|
||||||
|
// Generation time: 203.454s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
const CDN = 'https://esm.sh/';
|
||||||
|
|
||||||
|
async function hexchain(toml) {
|
||||||
|
const [tomlM, seedM, ssM, ajvM, ttM, dpM] = await Promise.all(
|
||||||
|
['smol-toml@1', 'seedrandom@3', 'simple-statistics@7', 'ajv@8', 'text-table@0.2', 'dompurify@3']
|
||||||
|
.map(p => import(CDN + p))
|
||||||
|
);
|
||||||
|
|
||||||
|
const config = tomlM.parse(toml);
|
||||||
|
const ajv = new ajvM.default();
|
||||||
|
const valid = ajv.validate({
|
||||||
|
type: 'object',
|
||||||
|
required: ['seed', 'count', 'label'],
|
||||||
|
properties: {
|
||||||
|
seed: { type: 'string' },
|
||||||
|
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||||
|
label: { type: 'string', minLength: 1 }
|
||||||
|
}
|
||||||
|
}, config);
|
||||||
|
if (!valid) return { valid: false, errors: ajv.errorsText() };
|
||||||
|
|
||||||
|
const rng = new seedM.default(config.seed);
|
||||||
|
const nums = Array.from({ length: config.count }, () => rng());
|
||||||
|
const r6 = x => Math.round(x * 1e6) / 1e6;
|
||||||
|
const mean = r6(ssM.mean(nums));
|
||||||
|
const stddev = r6(ssM.standardDeviation(nums));
|
||||||
|
const median = r6(ssM.median(nums));
|
||||||
|
|
||||||
|
const table = ttM.default([
|
||||||
|
['Stat', 'Value'],
|
||||||
|
['mean', String(mean)],
|
||||||
|
['stddev', String(stddev)],
|
||||||
|
['median', String(median)]
|
||||||
|
]);
|
||||||
|
|
||||||
|
const dp = dpM.default ?? dpM;
|
||||||
|
const purify = dp.sanitize ? dp : dp(window);
|
||||||
|
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
label: config.label,
|
||||||
|
stats: { mean, stddev, median },
|
||||||
|
table: purify.sanitize('<pre class="stats">' + table + '</pre>'),
|
||||||
|
count: config.count
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default hexchain;
|
||||||
|
// Generation time: 84.644s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
let libs;
|
||||||
|
|
||||||
|
const load = () => libs ??= Promise.all([
|
||||||
|
import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm'),
|
||||||
|
import('https://cdn.jsdelivr.net/npm/dompurify@3.1.5/+esm'),
|
||||||
|
]).then(([{ marked }, { default: purify }]) => ({ marked, purify }));
|
||||||
|
|
||||||
|
async function parseMarkdown(md) {
|
||||||
|
const { marked, purify } = await load();
|
||||||
|
const html = marked.parse(String(md ?? ''), { gfm: true });
|
||||||
|
return purify.sanitize(html, { USE_PROFILES: { html: true } });
|
||||||
|
}
|
||||||
|
export default parseMarkdown;
|
||||||
|
// Generation time: 40.071s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
|
||||||
|
const [{ default: Papa }, { groupBy: group, sumBy }] = await Promise.all([
|
||||||
|
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
|
||||||
|
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||||
|
]);
|
||||||
|
const num = r => +r[aggregateColumn] || 0;
|
||||||
|
const ops = {
|
||||||
|
sum: rs => sumBy(rs, num),
|
||||||
|
avg: rs => sumBy(rs, num) / rs.length,
|
||||||
|
count: rs => rs.length
|
||||||
|
};
|
||||||
|
if (!ops[operation]) throw new Error(`Unsupported operation: ${operation}`);
|
||||||
|
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||||
|
return Object.entries(group(data.filter(r => r[filterColumn] == filterValue), groupBy))
|
||||||
|
.map(([key, rows]) => ({ [groupBy]: key, result: ops[operation](rows) }));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default processCSV;
|
||||||
|
// Generation time: 79.891s
|
||||||
|
// Result: PASS
|
||||||
64
tests/7_scheduler/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
64
tests/7_scheduler/outputs/moonshotai_kimi-k3 EFF_medium.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
export async function findAvailableSlots(calendar1, calendar2, constraints) {
|
||||||
|
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
|
||||||
|
const utc = (s) => DateTime.fromISO(s, { zone: 'utc' });
|
||||||
|
const { durationMinutes, searchRange, workHours } = constraints;
|
||||||
|
const rs = utc(searchRange.start);
|
||||||
|
const re = utc(searchRange.end);
|
||||||
|
|
||||||
|
const busy = [...calendar1, ...calendar2]
|
||||||
|
.map(({ start, end }) => [utc(start), utc(end)])
|
||||||
|
.filter(([s, e]) => e > s)
|
||||||
|
.sort((a, b) => a[0] - b[0]);
|
||||||
|
|
||||||
|
const merged = [];
|
||||||
|
for (const [s, e] of busy) {
|
||||||
|
const last = merged.at(-1);
|
||||||
|
if (last && s <= last[1]) last[1] = e > last[1] ? e : last[1];
|
||||||
|
else merged.push([s, e]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const free = [];
|
||||||
|
let cur = rs;
|
||||||
|
for (const [s, e] of merged) {
|
||||||
|
const bs = s < rs ? rs : s;
|
||||||
|
const be = e > re ? re : e;
|
||||||
|
if (be <= rs || bs >= re) continue;
|
||||||
|
if (bs > cur) free.push([cur, bs]);
|
||||||
|
if (be > cur) cur = be;
|
||||||
|
}
|
||||||
|
if (cur < re) free.push([cur, re]);
|
||||||
|
|
||||||
|
const [sh, sm] = workHours.start.split(':').map(Number);
|
||||||
|
const [eh, em] = workHours.end.split(':').map(Number);
|
||||||
|
const windows = [];
|
||||||
|
for (let d = rs.startOf('day'); d < re; d = d.plus({ days: 1 })) {
|
||||||
|
const ws = d.plus({ hours: sh, minutes: sm });
|
||||||
|
let we = d.plus({ hours: eh, minutes: em });
|
||||||
|
if (we <= ws) we = we.plus({ days: 1 });
|
||||||
|
const s = ws > rs ? ws : rs;
|
||||||
|
const e = we < re ? we : re;
|
||||||
|
if (s < e) windows.push([s, e]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dur = { minutes: durationMinutes };
|
||||||
|
const iso = (d) => d.toISO({ suppressMilliseconds: true });
|
||||||
|
const slots = [];
|
||||||
|
for (const [fs, fe] of free) {
|
||||||
|
for (const [ws, we] of windows) {
|
||||||
|
if (we <= fs) continue;
|
||||||
|
if (ws >= fe) break;
|
||||||
|
let t = fs > ws ? fs : ws;
|
||||||
|
const end = fe < we ? fe : we;
|
||||||
|
while (true) {
|
||||||
|
const n = t.plus(dur);
|
||||||
|
if (n > end) break;
|
||||||
|
slots.push({ start: iso(t), end: iso(n) });
|
||||||
|
t = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slots;
|
||||||
|
}
|
||||||
|
export default findAvailableSlots;
|
||||||
|
// Generation time: 113.083s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
let ajvPromise;
|
||||||
|
|
||||||
|
const loadAjv = async () => {
|
||||||
|
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
|
||||||
|
import("https://esm.sh/ajv@8.17.1"),
|
||||||
|
import("https://esm.sh/ajv-formats@3.0.1"),
|
||||||
|
]);
|
||||||
|
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||||
|
addFormats(ajv);
|
||||||
|
return ajv;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAjv = () =>
|
||||||
|
(ajvPromise ??= loadAjv().catch((error) => {
|
||||||
|
ajvPromise = undefined;
|
||||||
|
throw error;
|
||||||
|
}));
|
||||||
|
|
||||||
|
async function validateJSON(data, schema) {
|
||||||
|
try {
|
||||||
|
const validate = (await getAjv()).compile(schema);
|
||||||
|
const valid = validate(data);
|
||||||
|
return {
|
||||||
|
valid,
|
||||||
|
errors: (validate.errors ?? []).map(
|
||||||
|
({ instancePath, message }) => `${instancePath || "(root)"} ${message}`,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return { valid: false, errors: [error?.message ?? String(error)] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default validateJSON;
|
||||||
|
// Generation time: 91.986s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||||
|
const { scaleLinear, line } = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
|
||||||
|
const data = [];
|
||||||
|
let ema;
|
||||||
|
|
||||||
|
for await (const { timestamp, value } of asyncIterable) {
|
||||||
|
ema = data.length ? alpha * value + (1 - alpha) * ema : value;
|
||||||
|
data.push({ timestamp, value, ema });
|
||||||
|
if (data.length > maxPoints) data.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data.length) return { data, path: "" };
|
||||||
|
|
||||||
|
const x = scaleLinear()
|
||||||
|
.domain([data[0].timestamp, data.at(-1).timestamp])
|
||||||
|
.range([0, width]);
|
||||||
|
const y = scaleLinear().domain(yDomain).range([height, 0]);
|
||||||
|
|
||||||
|
const path = line()
|
||||||
|
.x(d => x(d.timestamp))
|
||||||
|
.y(d => y(d.ema))(data);
|
||||||
|
|
||||||
|
return { data, path };
|
||||||
|
}
|
||||||
|
export default createStreamVisualizer;
|
||||||
|
// Generation time: 48.702s
|
||||||
|
// Result: PASS
|
||||||
Reference in New Issue
Block a user