Compare commits

...

2 Commits

Author SHA1 Message Date
github-actions[bot]
48dfa6cd44 Docs: Update benchmark for anthropic/claude-sonnet-5 EFF:high 2026-07-01 22:16:12 +00:00
0c2cd5e395 Update README 2026-07-01 15:12:41 -07:00
13 changed files with 442 additions and 0 deletions

1
README
View File

@@ -9,6 +9,7 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
The following models are included in the benchmark run.
<!-- MODELS_START -->
anthropic/claude-sonnet-5 EFF:high
z-ai/glm-5.2
moonshotai/kimi-k2.7-code
anthropic/claude-fable-5

View File

@@ -0,0 +1,15 @@
async function hashPassword(password, salt) {
const { default: scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm');
const enc = new TextEncoder();
const passBuf = enc.encode(password);
const saltBuf = enc.encode(salt);
const N = 1024, r = 8, p = 1, dkLen = 32;
const derivedKey = await scrypt(passBuf, saltBuf, N, r, p, dkLen);
return Array.from(derivedKey, b => b.toString(16).padStart(2, '0')).join('');
}
export default hashPassword;
// Generation time: 4.636s
// Result: FAIL

View File

@@ -0,0 +1,17 @@
async function analyzeGPS(readings, boundary) {
const turf = await import('https://esm.sh/@turf/turf@6');
const valid = readings
.filter(r => turf.booleanPointInPolygon(turf.point(r.loc), boundary))
.sort((a, b) => a.ts - b.ts);
if (valid.length < 2) return 0;
const line = turf.lineString(valid.map(r => r.loc));
const km = turf.length(line, { units: 'kilometers' });
return Math.round(km * 100) / 100;
}
export default analyzeGPS;
// Generation time: 4.282s
// Result: PASS

View File

@@ -0,0 +1,58 @@
async function computeMST(tomlString) {
const [{ parse }, { Heap }, { default: textTable }] = await Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/mnemonist'),
import('https://esm.sh/text-table'),
]);
const { edges = [] } = parse(tomlString);
if (!Array.isArray(edges) || edges.length === 0) {
return { table: textTable([['From', 'To', 'Weight']]), totalWeight: 0 };
}
class UnionFind {
constructor(nodes) {
this.parent = new Map(nodes.map(n => [n, n]));
this.rank = new Map(nodes.map(n => [n, 0]));
}
find(x) {
let p = this.parent.get(x);
if (p !== x) { p = this.find(p); this.parent.set(x, p); }
return p;
}
union(a, b) {
let ra = this.find(a), rb = this.find(b);
if (ra === rb) return false;
const rkA = this.rank.get(ra), rkB = this.rank.get(rb);
if (rkA < rkB) [ra, rb] = [rb, ra];
this.parent.set(rb, ra);
if (rkA === rkB) this.rank.set(ra, rkA + 1);
return true;
}
}
const heap = new Heap((a, b) => a.weight - b.weight);
edges.forEach(e => heap.push(e));
const nodeSet = new Set();
edges.forEach(({ from, to }) => { nodeSet.add(from); nodeSet.add(to); });
const uf = new UnionFind([...nodeSet]);
const target = nodeSet.size - 1;
const mst = [];
let totalWeight = 0;
while (heap.size > 0 && mst.length < target) {
const { from, to, weight } = heap.pop();
if (uf.union(from, to)) {
mst.push([from, to, String(weight)]);
totalWeight += weight;
}
}
const rows = [['From', 'To', 'Weight'], ...mst];
return { table: textTable(rows), totalWeight };
}
export default computeMST;
// Generation time: 24.146s
// Result: PASS

View File

@@ -0,0 +1,34 @@
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue@0.1.5');
if (!(start in graph) || !(end in graph)) return Infinity;
const dist = Object.fromEntries(Object.keys(graph).map(n => [n, Infinity]));
dist[start] = 0;
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
pq.queue({ node: start, dist: 0 });
const visited = new Set();
while (pq.length > 0) {
const { node, dist: d } = pq.dequeue();
if (visited.has(node)) continue;
visited.add(node);
if (node === end) return d;
for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) {
const newDist = d + weight;
if (newDist < dist[neighbor]) {
dist[neighbor] = newDist;
pq.queue({ node: neighbor, dist: newDist });
}
}
}
return dist[end];
}
export default findShortestPath;
// Generation time: 10.596s
// Result: PASS

View File

@@ -0,0 +1,25 @@
async function findConvexHull(points) {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash-es/lodash.js');
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const pts = _.sortBy(_.uniqWith(points, _.isEqual), ['x', 'y']);
if (pts.length < 3) return pts;
const build = (arr) => {
const hull = [];
for (const p of arr) {
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) hull.pop();
hull.push(p);
}
return hull;
};
const lower = build(pts);
const upper = build([...pts].reverse());
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
}
export default findConvexHull;
// Generation time: 9.472s
// Result: PASS

View File

@@ -0,0 +1,60 @@
async function analyzeSignal(yamlString) {
const [
{ default: yaml },
{ default: math },
{ default: ndarray },
{ default: fft },
{ default: DOMPurify },
] = await Promise.all([
import('https://esm.sh/js-yaml@4'),
import('https://esm.sh/mathjs@12'),
import('https://esm.sh/ndarray@1'),
import('https://esm.sh/ndarray-fft@1'),
import('https://esm.sh/dompurify@3'),
]);
const config = yaml.load(yamlString);
const { sampleRate, duration, components } = config;
const N = sampleRate * duration;
const signal = Array.from({ length: N }, (_, i) => {
const t = i / sampleRate;
return components.reduce(
(sum, { frequency, amplitude }) =>
sum + amplitude * math.sin(2 * math.pi * frequency * t),
0
);
});
const real = ndarray(new Float64Array(signal));
const imag = ndarray(new Float64Array(N));
fft(1, real, imag);
const half = N / 2;
const magnitude = Array.from({ length: half + 1 }, (_, k) => {
const re = real.get(k);
const im = imag.get(k);
return math.sqrt(re * re + im * im) / half;
});
const peaks = magnitude
.map((mag, k) => ({ frequencyHz: (k * sampleRate) / N, magnitude: mag }))
.filter(({ magnitude }) => magnitude > 0.1)
.sort((a, b) => b.magnitude - a.magnitude)
.map(({ frequencyHz, magnitude }) => ({
frequencyHz: Math.round(frequencyHz),
magnitude: Math.round(magnitude * 100) / 100,
}));
const rows = peaks
.map(({ frequencyHz, magnitude }) => `<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`)
.join('');
const rawHtml = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`;
const html = DOMPurify.sanitize(rawHtml);
return { peaks, html, signalLength: N };
}
export default analyzeSignal;
// Generation time: 8.829s
// Result: FAIL

View File

@@ -0,0 +1,73 @@
const CDN = {
toml: 'https://esm.sh/smol-toml@1',
seedrandom: 'https://esm.sh/seedrandom@3',
stats: 'https://esm.sh/simple-statistics@7',
ajv: 'https://esm.sh/ajv@8',
table: 'https://esm.sh/text-table@1',
dompurify: 'https://esm.sh/dompurify@3',
};
const SCHEMA = {
type: 'object',
required: ['seed', 'count', 'label'],
properties: {
seed: { type: 'string' },
count: { type: 'integer', minimum: 1, maximum: 10000 },
label: { type: 'string', minLength: 1 },
},
};
const round6 = n => Math.round(n * 1e6) / 1e6;
async function hexchain(tomlStr) {
const [{ parse }, seedrandomMod, ss, AjvMod, tableMod, DOMPurify] = await Promise.all([
import(CDN.toml),
import(CDN.seedrandom),
import(CDN.stats),
import(CDN.ajv),
import(CDN.table),
import(CDN.dompurify),
]);
const seedrandom = seedrandomMod.default;
const Ajv = AjvMod.default;
const table = tableMod.default;
const purify = DOMPurify.default ?? DOMPurify;
const config = parse(tomlStr);
const ajv = new Ajv();
const validate = ajv.compile(SCHEMA);
if (!validate(config)) {
return { valid: false, errors: ajv.errorsText(validate.errors) };
}
const rng = new seedrandom(config.seed);
const numbers = Array.from({ length: config.count }, () => rng());
const mean = round6(ss.mean(numbers));
const stddev = round6(ss.standardDeviation(numbers));
const median = round6(ss.median(numbers));
const rows = [
['Stat', 'Value'],
['mean', String(mean)],
['stddev', String(stddev)],
['median', String(median)],
];
const tableStr = table(rows);
const rawHtml = `<pre class="stats">${tableStr}</pre>`;
const sanitizedHtml = purify.sanitize(rawHtml);
return {
valid: true,
label: config.label,
stats: { mean, stddev, median },
table: sanitizedHtml,
count: config.count,
};
}
export default hexchain;
// Generation time: 10.215s
// Result: FAIL

View File

@@ -0,0 +1,14 @@
async function parseMarkdown(markdown) {
const [{ marked }, DOMPurify] = await Promise.all([
import('https://esm.sh/marked@12'),
import('https://esm.sh/dompurify@3').then(m => m.default),
]);
marked.setOptions({ gfm: true, breaks: true });
const rawHtml = marked.parse(markdown ?? '');
return DOMPurify.sanitize(rawHtml);
}
export default parseMarkdown;
// Generation time: 4.740s
// Result: PASS

View File

@@ -0,0 +1,29 @@
async function processCSV(csvString, config) {
const { filterColumn, filterValue, groupBy: groupCol, aggregateColumn, operation } = config;
const [{ default: Papa }, { groupBy }] = await Promise.all([
import('https://esm.sh/papaparse@5.4.1'),
import('https://esm.sh/lodash-es@4.17.21'),
]);
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
const filtered = data.filter(row => row[filterColumn] == filterValue);
const groups = groupBy(filtered, row => row[groupCol]);
return Object.entries(groups).map(([key, rows]) => {
const values = rows.map(row => Number(row[aggregateColumn]) || 0);
const sum = values.reduce((acc, v) => acc + v, 0);
const result =
operation === 'sum' ? sum :
operation === 'avg' ? sum / values.length :
values.length;
return { [groupCol]: key, result };
});
}
export default processCSV;
// Generation time: 8.882s
// Result: PASS

View File

@@ -0,0 +1,62 @@
async function findAvailableSlots(calendarA, calendarB, constraints) {
const { parseISO, addMinutes, addDays, startOfDay, max, min } =
await import('https://esm.sh/date-fns@3');
const toRange = c => ({ start: parseISO(c.start), end: parseISO(c.end) });
const busy = [...calendarA, ...calendarB]
.map(toRange)
.sort((a, b) => a.start - b.start);
const merged = [];
for (const slot of busy) {
const last = merged[merged.length - 1];
if (last && slot.start <= last.end) last.end = max([last.end, slot.end]);
else merged.push({ ...slot });
}
const searchStart = parseISO(constraints.searchRange.start);
const searchEnd = parseISO(constraints.searchRange.end);
const duration = constraints.durationMinutes;
const free = [];
let cursor = searchStart;
for (const b of merged) {
if (b.start >= searchEnd) break;
if (b.end <= searchStart) continue;
if (b.start > cursor) free.push({ start: cursor, end: min([b.start, searchEnd]) });
cursor = max([cursor, b.end]);
}
if (cursor < searchEnd) free.push({ start: cursor, end: searchEnd });
const [wsH, wsM] = constraints.workHours.start.split(':').map(Number);
const [weH, weM] = constraints.workHours.end.split(':').map(Number);
const slots = [];
for (const period of free) {
let dayStart = startOfDay(period.start);
while (dayStart < period.end) {
const y = dayStart.getUTCFullYear(), m = dayStart.getUTCMonth(), d = dayStart.getUTCDate();
const workStart = new Date(Date.UTC(y, m, d, wsH, wsM));
const workEnd = new Date(Date.UTC(y, m, d, weH, weM));
const windowStart = max([workStart, period.start]);
const windowEnd = min([workEnd, period.end]);
let slotStart = windowStart;
while (addMinutes(slotStart, duration) <= windowEnd) {
const slotEnd = addMinutes(slotStart, duration);
slots.push({ start: slotStart.toISOString(), end: slotEnd.toISOString() });
slotStart = slotEnd;
}
dayStart = addDays(dayStart, 1);
}
}
return slots;
}
export default findAvailableSlots;
// Generation time: 26.434s
// Result: PASS

View File

@@ -0,0 +1,22 @@
async function validateJSON(data, schema) {
const { default: Ajv } = await import('https://cdn.jsdelivr.net/npm/ajv@8/+esm');
const ajv = new Ajv({ allErrors: true, strict: false });
const validate = ajv.compile(schema);
const valid = validate(data);
const errors = valid
? []
: validate.errors.map(({ instancePath, message, params }) => {
const path = instancePath || '/';
const extra = params?.missingProperty
? ` (missing: ${params.missingProperty})`
: '';
return `${path}: ${message}${extra}`;
});
return { valid, errors };
}
export default validateJSON;
// Generation time: 6.311s
// Result: PASS

View File

@@ -0,0 +1,32 @@
async function createStreamVisualizer(asyncIterable, options) {
const { maxPoints, alpha, width, height, yDomain } = options;
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
const data = [];
let prevEma;
for await (const { timestamp, value } of asyncIterable) {
prevEma = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
data.push({ timestamp, value, ema: prevEma });
if (data.length > maxPoints) data.shift();
}
if (!data.length) return { data, path: '' };
const x = d3.scaleLinear()
.domain([data[0].timestamp, data[data.length - 1].timestamp])
.range([0, width]);
const y = d3.scaleLinear()
.domain(yDomain)
.range([height, 0]);
const line = d3.line()
.x(d => x(d.timestamp))
.y(d => y(d.ema));
return { data, path: line(data) };
}
export default createStreamVisualizer;
// Generation time: 5.834s
// Result: PASS