Docs: Update benchmark for anthropic/claude-opus-4.8 EFF:medium

This commit is contained in:
github-actions[bot]
2026-05-31 18:07:47 +00:00
parent 39d0a9f316
commit e5f1b816d1
12 changed files with 413 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
const hashPassword = async (password, salt) => {
const { scrypt } = await import("https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm");
const enc = new TextEncoder();
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
return [...hash].map(b => b.toString(16).padStart(2, "0")).join("");
};
export default hashPassword;
// Generation time: 2.918s
// Result: PASS

View File

@@ -0,0 +1,12 @@
async function analyzeGPS(readings, boundary) {
const turf = await import("https://cdn.skypack.dev/@turf/turf");
const inside = readings
.filter((r) => turf.booleanPointInPolygon(turf.point(r.loc), boundary))
.sort((a, b) => a.ts - b.ts);
if (inside.length < 2) return 0;
const line = turf.lineString(inside.map((r) => r.loc));
return Math.round(turf.length(line, { units: "kilometers" }) * 100) / 100;
}
export default analyzeGPS;
// Generation time: 2.996s
// Result: FAIL

View File

@@ -0,0 +1,71 @@
async function computeMST(toml) {
const [{ parse }, mnemonist, textTableMod] = await Promise.all([
import("https://esm.sh/smol-toml"),
import("https://esm.sh/mnemonist"),
import("https://esm.sh/text-table")
]);
const Heap = mnemonist.Heap || mnemonist.default.Heap;
const table = textTableMod.default || textTableMod;
const edges = parse(toml).edges || [];
const heap = new Heap((a, b) => a.weight - b.weight);
const nodes = new Set();
for (const e of edges) {
heap.push(e);
nodes.add(e.from);
nodes.add(e.to);
}
const parent = new Map();
const rank = new Map();
for (const n of nodes) {
parent.set(n, n);
rank.set(n, 0);
}
const find = x => {
let r = x;
while (parent.get(r) !== r) r = parent.get(r);
while (parent.get(x) !== r) {
const next = parent.get(x);
parent.set(x, r);
x = next;
}
return r;
};
const union = (a, b) => {
const ra = find(a), rb = find(b);
if (ra === rb) return false;
const da = rank.get(ra), db = rank.get(rb);
if (da < db) parent.set(ra, rb);
else if (da > db) parent.set(rb, ra);
else {
parent.set(rb, ra);
rank.set(ra, da + 1);
}
return true;
};
const rows = [];
let totalWeight = 0;
const need = Math.max(nodes.size - 1, 0);
while (heap.size && rows.length < need) {
const e = heap.pop();
if (union(e.from, e.to)) {
rows.push([e.from, e.to, String(e.weight)]);
totalWeight += e.weight;
}
}
return {
table: table([["From", "To", "Weight"], ...rows]),
totalWeight
};
}
export default computeMST;
// Generation time: 8.341s
// Result: PASS

View File

@@ -0,0 +1,24 @@
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import("https://esm.sh/js-priority-queue");
const dist = {};
for (const node in graph) dist[node] = Infinity;
dist[start] = 0;
const pq = new PriorityQueue({ comparator: (a, b) => a.cost - b.cost });
pq.queue({ node: start, cost: 0 });
while (pq.length) {
const { node, cost } = pq.dequeue();
if (node === end) return cost;
if (cost > dist[node]) continue;
for (const next in graph[node]) {
const nc = cost + graph[node][next];
if (nc < dist[next]) {
dist[next] = nc;
pq.queue({ node: next, cost: nc });
}
}
}
return dist[end] ?? Infinity;
}
export default findShortestPath;
// Generation time: 5.506s
// Result: PASS

View File

@@ -0,0 +1,29 @@
const findConvexHull = async (points) => {
const { default: _ } = await import("https://cdn.skypack.dev/lodash");
const pts = _.sortBy(
_.uniqBy(points, (p) => `${p.x},${p.y}`),
["x", "y"]
);
if (pts.length < 3) return pts;
const cross = (o, a, b) =>
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const build = (arr) => {
const h = [];
for (const p of arr) {
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0)
h.pop();
h.push(p);
}
h.pop();
return h;
};
return [...build(pts), ...build([...pts].reverse())];
};
export default findConvexHull;
// Generation time: 4.735s
// Result: PASS

View File

@@ -0,0 +1,65 @@
const CDN = {
yaml: "https://cdn.jsdelivr.net/npm/js-yaml/+esm",
math: "https://cdn.jsdelivr.net/npm/mathjs/+esm",
ndarray: "https://cdn.jsdelivr.net/npm/ndarray/+esm",
fft: "https://cdn.jsdelivr.net/npm/ndarray-fft/+esm",
purify: "https://cdn.jsdelivr.net/npm/dompurify/+esm"
};
const def = m => m.default ?? m;
export async function analyzeSignal(yamlStr) {
const [yamlMod, math, ndMod, fftMod, purifyMod] = await Promise.all([
import(CDN.yaml),
import(CDN.math),
import(CDN.ndarray),
import(CDN.fft),
import(CDN.purify)
]);
const yaml = def(yamlMod);
const ndarray = def(ndMod);
const fft = def(fftMod);
const DOMPurify = def(purifyMod);
const cfg = yaml.load(yamlStr);
const { sampleRate, duration, components = [] } = cfg;
const N = sampleRate * duration;
const signal = Array.from({ length: N }, (_, i) => {
const t = i / sampleRate;
return components.reduce(
(s, { amplitude, frequency }) =>
s + amplitude * math.sin(2 * math.pi * frequency * t),
0
);
});
const real = ndarray(new Float64Array(signal), [N]);
const imag = ndarray(new Float64Array(N), [N]);
fft(1, real, imag);
const half = N / 2;
const peaks = [];
for (let k = 0; k <= half; k++) {
const mag = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half;
if (mag > 0.1)
peaks.push({
frequencyHz: Math.round((k * sampleRate) / N),
magnitude: Math.round(mag * 100) / 100
});
}
peaks.sort((a, b) => b.magnitude - a.magnitude);
const rows = peaks
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.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 };
}
export default analyzeSignal;
// Generation time: 11.820s
// Result: PASS

View File

@@ -0,0 +1,67 @@
const CDN = "https://esm.sh/";
const hexchain = async (toml) => {
const [
{ parse },
{ default: seedrandom },
ss,
{ default: Ajv },
{ default: table },
{ default: DOMPurify }
] = await Promise.all([
import(`${CDN}smol-toml`),
import(`${CDN}seedrandom`),
import(`${CDN}simple-statistics`),
import(`${CDN}ajv`),
import(`${CDN}text-table`),
import(`${CDN}dompurify`)
]);
const config = parse(toml);
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 ajv = new Ajv();
if (!ajv.validate(schema, config))
return { valid: false, errors: ajv.errorsText() };
const rng = new seedrandom(config.seed);
const nums = Array.from({ length: config.count }, () => rng());
const r = (n) => Math.round(n * 1e6) / 1e6;
const mean = r(ss.mean(nums));
const stddev = r(ss.standardDeviation(nums));
const median = r(ss.median(nums));
const tableString = table([
["Stat", "Value"],
["mean", String(mean)],
["stddev", String(stddev)],
["median", String(median)]
]);
const sanitized = DOMPurify.sanitize(
`<pre class="stats">${tableString}</pre>`
);
return {
valid: true,
label: config.label,
stats: { mean, stddev, median },
table: sanitized,
count: config.count
};
};
export { hexchain };
export default hexchain;
// Generation time: 8.247s
// Result: PASS

View File

@@ -0,0 +1,9 @@
const parseMarkdown = async (md = "") => {
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/+esm");
return marked.parse(md, { gfm: true, breaks: true });
};
export default parseMarkdown;
// Generation time: 6.625s
// Result: PASS

View File

@@ -0,0 +1,29 @@
const processCSV = async (csv, config) => {
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
const [{ default: Papa }, { default: _ }] = await Promise.all([
import("https://esm.sh/papaparse@5.4.1"),
import("https://esm.sh/lodash-es@4.17.21")
]);
const { data } = Papa.parse(csv.trim(), { header: true, skipEmptyLines: true });
const num = v => {
const n = Number(v);
return isNaN(n) ? 0 : n;
};
const filtered = data.filter(r => r[filterColumn] == filterValue);
const groups = _.groupBy(filtered, r => r[groupBy]);
return _.map(groups, (rows, key) => {
const vals = rows.map(r => num(r[aggregateColumn]));
const sum = _.sum(vals);
const result =
operation === "sum" ? sum :
operation === "avg" ? sum / rows.length :
rows.length;
return { [groupBy]: key, result };
});
};
export default processCSV;
// Generation time: 6.170s
// Result: PASS

View File

@@ -0,0 +1,53 @@
async function findAvailableSlots(cal1, cal2, constraints) {
const { DateTime } = await import('https://cdn.skypack.dev/luxon');
const { durationMinutes: dur, searchRange, workHours } = constraints;
const opt = { zone: 'utc' };
const toDT = s => DateTime.fromISO(s, opt);
const rs = toDT(searchRange.start), re = toDT(searchRange.end);
const [wsH, wsM] = workHours.start.split(':').map(Number);
const [weH, weM] = workHours.end.split(':').map(Number);
const busy = [...cal1, ...cal2]
.map(b => [toDT(b.start), toDT(b.end)])
.filter(([s, e]) => e > s)
.sort((a, b) => a[0] - b[0]);
const merged = [];
for (const [s, e] of busy) {
const last = merged[merged.length - 1];
if (last && s <= last[1]) {
if (e > last[1]) last[1] = e;
} else merged.push([s, e]);
}
const slots = [];
for (let day = rs.startOf('day'); day < re; day = day.plus({ days: 1 })) {
const ws = day.set({ hour: wsH, minute: wsM, second: 0, millisecond: 0 });
const we = day.set({ hour: weH, minute: weM, second: 0, millisecond: 0 });
const winS = ws > rs ? ws : rs;
const winE = we < re ? we : re;
if (winS >= winE) continue;
const free = [];
let cur = winS;
for (const [bs, be] of merged) {
if (be <= cur || bs >= winE) continue;
if (bs > cur) free.push([cur, bs]);
if (be > cur) cur = be;
if (cur >= winE) break;
}
if (cur < winE) free.push([cur, winE]);
for (const [fs, fe] of free) {
let start = fs;
for (let nxt; (nxt = start.plus({ minutes: dur })) <= fe; start = nxt) {
slots.push({ start: start.toUTC().toISO(), end: nxt.toUTC().toISO() });
}
}
}
return slots.sort((a, b) => (a.start < b.start ? -1 : 1));
}
export default findAvailableSlots;
// Generation time: 22.608s
// Result: PASS

View File

@@ -0,0 +1,23 @@
const validateJSON = async (data, schema) => {
try {
const { default: Ajv } = await import("https://esm.sh/ajv@8");
const ajv = new Ajv({ allErrors: true, strict: false });
const validate = ajv.compile(schema);
const valid = validate(data);
return {
valid,
errors: valid
? []
: (validate.errors || []).map(
(e) => `${e.instancePath || "/"} ${e.message}`.trim()
),
};
} catch (err) {
return { valid: false, errors: [err.message] };
}
};
export { validateJSON };
export default validateJSON;
// Generation time: 5.406s
// Result: PASS

View File

@@ -0,0 +1,22 @@
async function createStreamVisualizer(asyncIterable, options) {
const { maxPoints, alpha, width, height, yDomain } = options;
const { scaleLinear, line } = await import("https://cdn.skypack.dev/d3");
const data = [];
let prevEma;
for await (const value of asyncIterable) {
prevEma = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
data.push({ timestamp: Date.now(), value, ema: prevEma });
if (data.length > maxPoints) data.splice(0, data.length - maxPoints);
}
const x = scaleLinear()
.domain([data[0]?.timestamp ?? 0, data.at(-1)?.timestamp ?? 1])
.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: 4.318s
// Result: FAIL