Docs: Update benchmark for anthropic/claude-sonnet-4.6

This commit is contained in:
github-actions[bot]
2026-02-17 22:10:27 +00:00
parent ceeeb7d186
commit 79886a435d
12 changed files with 350 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/scrypt.js/+esm"));
const enc = new TextEncoder();
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
return Array.from(hash).map(b => b.toString(16).padStart(2, "0")).join("");
};
export default hashPassword;
// Generation time: 2.204s
// Result: PASS

View File

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

View File

@@ -0,0 +1,46 @@
async function computeMST(tomlString) {
const [{ parse }, { default: Heap }, { default: textTable }] = await Promise.all([
import("https://esm.sh/smol-toml"),
import("https://esm.sh/mnemonist/heap.js"),
import("https://esm.sh/text-table"),
]);
const { edges } = parse(tomlString);
const heap = new Heap((a, b) => a.weight - b.weight);
edges.forEach(e => heap.push(e));
const nodes = [...new Set(edges.flatMap(e => [e.from, e.to]))];
const parent = Object.fromEntries(nodes.map(n => [n, n]));
const rank = Object.fromEntries(nodes.map(n => [n, 0]));
const find = n => {
if (parent[n] !== n) parent[n] = find(parent[n]);
return parent[n];
};
const union = (a, b) => {
const [ra, rb] = [find(a), find(b)];
if (ra === rb) return false;
if (rank[ra] < rank[rb]) parent[ra] = rb;
else if (rank[ra] > rank[rb]) parent[rb] = ra;
else { parent[rb] = ra; rank[ra]++; }
return true;
};
const mstEdges = [];
const limit = nodes.length - 1;
while (heap.size && mstEdges.length < limit) {
const { from, to, weight } = heap.pop();
if (union(from, to)) mstEdges.push([from, to, String(weight)]);
}
const totalWeight = mstEdges.reduce((s, [,, w]) => s + Number(w), 0);
const table = textTable([["From", "To", "Weight"], ...mstEdges]);
return { table, totalWeight };
}
export default computeMST;
// Generation time: 5.943s
// Result: PASS

View File

@@ -0,0 +1,31 @@
const findShortestPath = async (graph, start, end) => {
const { default: PriorityQueue } = await import(
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.js"
);
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
const dist = Object.fromEntries(Object.keys(graph).map((n) => [n, Infinity]));
dist[start] = 0;
pq.queue([0, start]);
while (pq.length) {
const [d, u] = pq.dequeue();
if (d > dist[u]) continue;
if (u === end) return d;
for (const [v, w] of Object.entries(graph[u] ?? {})) {
const nd = d + w;
if (nd < dist[v]) {
dist[v] = nd;
pq.queue([nd, v]);
}
}
}
return dist[end];
};
export default findShortestPath;
// Generation time: 4.396s
// Result: FAIL

View File

@@ -0,0 +1,26 @@
async function findConvexHull(points) {
const { default: _ } = await import("https://cdn.skypack.dev/lodash");
const unique = _.uniqWith(points, _.isEqual);
const sorted = _.sortBy(unique, ["x", "y"]);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) =>
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHalf = (pts) =>
pts.reduce((hull, p) => {
while (hull.length >= 2 && cross(hull.at(-2), hull.at(-1), p) <= 0)
hull.pop();
return [...hull, p];
}, []);
const lower = buildHalf(sorted);
const upper = buildHalf([...sorted].reverse());
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
}
export default findConvexHull;
// Generation time: 3.848s
// Result: PASS

View File

@@ -0,0 +1,17 @@
async function findLISLength(nums) {
if (!nums?.length) return 0;
const { bisectLeft } = await import("https://cdn.skypack.dev/d3-array");
const tails = [];
for (const n of nums) {
const i = bisectLeft(tails, n);
tails[i] = n;
}
return tails.length;
}
export default findLISLength;
// Generation time: 1.943s
// Result: PASS

View File

@@ -0,0 +1,9 @@
const renderTemplate = async (template, data) => {
const { default: Handlebars } = await import(
"https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.esm.min.js"
);
return Handlebars.compile(template)(data);
};
export default renderTemplate;
// Generation time: 1.675s
// Result: FAIL

View File

@@ -0,0 +1,7 @@
const parseMarkdown = async (markdown) => {
const { marked } = await import("https://cdn.jsdelivr.net/npm/marked/src/marked.esm.js");
return marked.parse(markdown);
};
export default parseMarkdown;
// Generation time: 1.296s
// Result: FAIL

View File

@@ -0,0 +1,30 @@
async function processCSV(csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
const [{ default: Papa }] = await Promise.all([
import("https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm"),
]);
const { data } = Papa.parse(csvString.trim(), { header: true, skipEmptyLines: true });
const filtered = data.filter(row => row[filterColumn] == filterValue);
const groups = filtered.reduce((acc, row) => {
const key = row[groupBy];
(acc[key] ??= []).push(row);
return acc;
}, {});
const toNum = v => { const n = Number(v); return isNaN(n) ? 0 : n; };
return Object.entries(groups).map(([groupValue, rows]) => {
const vals = rows.map(r => toNum(r[aggregateColumn]));
const sum = vals.reduce((a, b) => a + b, 0);
const result =
operation === "sum" ? sum :
operation === "avg" ? sum / rows.length :
operation === "count" ? rows.length : 0;
return { [groupBy]: groupValue, result };
});
}
export default processCSV;
// Generation time: 4.438s
// Result: PASS

View File

@@ -0,0 +1,106 @@
async function findAvailableSlots(calendar1, calendar2, constraints) {
const { default: dayjs } = await import("https://cdn.skypack.dev/dayjs@1.11.10");
const { default: utc } = await import("https://cdn.skypack.dev/dayjs@1.11.10/plugin/utc");
const { default: customParseFormat } = await import("https://cdn.skypack.dev/dayjs@1.11.10/plugin/customParseFormat");
dayjs.extend(utc);
dayjs.extend(customParseFormat);
const { durationMinutes, searchRange, workHours } = constraints;
const d = (iso) => dayjs.utc(iso);
const durationMs = durationMinutes * 60 * 1000;
const mergedBusy = mergeBusySlots(
[...calendar1, ...calendar2].map((s) => ({ start: d(s.start), end: d(s.end) }))
);
const rangeStart = d(searchRange.start);
const rangeEnd = d(searchRange.end);
const freeSlots = extractFreeSlots(mergedBusy, rangeStart, rangeEnd);
return freeSlots.flatMap((free) =>
generateSlots(free.start, free.end, durationMs, workHours, dayjs)
);
}
function mergeBusySlots(slots) {
if (!slots.length) return [];
const sorted = slots.slice().sort((a, b) => a.start.valueOf() - b.start.valueOf());
return sorted.reduce((merged, curr) => {
if (!merged.length) return [{ ...curr }];
const last = merged[merged.length - 1];
if (curr.start.valueOf() <= last.end.valueOf()) {
last.end = curr.end.valueOf() > last.end.valueOf() ? curr.end : last.end;
} else {
merged.push({ ...curr });
}
return merged;
}, []);
}
function extractFreeSlots(busySlots, rangeStart, rangeEnd) {
const free = [];
let cursor = rangeStart;
for (const busy of busySlots) {
if (busy.start.valueOf() > cursor.valueOf()) {
const freeEnd = busy.start.valueOf() < rangeEnd.valueOf() ? busy.start : rangeEnd;
if (freeEnd.valueOf() > cursor.valueOf()) {
free.push({ start: cursor, end: freeEnd });
}
}
if (busy.end.valueOf() > cursor.valueOf()) {
cursor = busy.end;
}
if (cursor.valueOf() >= rangeEnd.valueOf()) break;
}
if (cursor.valueOf() < rangeEnd.valueOf()) {
free.push({ start: cursor, end: rangeEnd });
}
return free;
}
function generateSlots(freeStart, freeEnd, durationMs, workHours, dayjs) {
const [whStartH, whStartM] = workHours.start.split(":").map(Number);
const [whEndH, whEndM] = workHours.end.split(":").map(Number);
const slots = [];
let dayDate = freeStart.utc().startOf("day");
const lastDay = freeEnd.utc().startOf("day");
while (dayDate.valueOf() <= lastDay.valueOf()) {
const wStart = dayDate.hour(whStartH).minute(whStartM).second(0).millisecond(0);
const wEnd = dayDate.hour(whEndH).minute(whEndM).second(0).millisecond(0);
const slotStart = Math.max(freeStart.valueOf(), wStart.valueOf());
const slotEnd = Math.min(freeEnd.valueOf(), wEnd.valueOf());
let cursor = alignToSlot(slotStart, wStart.valueOf(), durationMs);
while (cursor + durationMs <= slotEnd) {
slots.push({
start: dayjs.utc(cursor).toISOString(),
end: dayjs.utc(cursor + durationMs).toISOString(),
});
cursor += durationMs;
}
dayDate = dayDate.add(1, "day");
}
return slots;
}
function alignToSlot(ts, workDayStart, durationMs) {
const offset = ts - workDayStart;
const remainder = offset % durationMs;
return remainder === 0 ? ts : ts + (durationMs - remainder);
}
export default findAvailableSlots;
// Generation time: 13.592s
// Result: FAIL

View File

@@ -0,0 +1,23 @@
async function validateJSON(data, schema) {
const CDN = "https://cdn.jsdelivr.net/npm/ajv@8/dist/ajv2020.min.js";
const module = await import(CDN);
const Ajv = module.default ?? module;
const ajv = new Ajv({ allErrors: true, strict: false });
const validate = ajv.compile(schema);
const valid = validate(data);
return {
valid,
errors: valid
? []
: validate.errors.map(
({ instancePath, message, params }) =>
`${instancePath || "root"}: ${message} ${JSON.stringify(params)}`
),
};
}
export default validateJSON;
// Generation time: 3.415s
// Result: FAIL

View File

@@ -0,0 +1,31 @@
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 = null;
for await (const { timestamp, value } of asyncIterable) {
const ema = prevEma === null ? value : alpha * value + (1 - alpha) * prevEma;
prevEma = ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
const xScale = scaleLinear()
.domain([data[0].timestamp, data[data.length - 1].timestamp])
.range([0, width]);
const yScale = scaleLinear()
.domain(yDomain)
.range([height, 0]);
const path = line()
.x(d => xScale(d.timestamp))
.y(d => yScale(d.ema))(data);
return { data, path };
}
export default createStreamVisualizer;
// Generation time: 3.557s
// Result: PASS