mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-06-27 20:02:14 +00:00
Docs: Update benchmark for anthropic/claude-fable-5
This commit is contained in:
9
tests/10_scrypt_hash/outputs/anthropic_claude-fable-5.js
Normal file
9
tests/10_scrypt_hash/outputs/anthropic_claude-fable-5.js
Normal 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: 5.733s
|
||||
// Result: PASS
|
||||
12
tests/11_geospatial/outputs/anthropic_claude-fable-5.js
Normal file
12
tests/11_geospatial/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const analyzeGPS = async (readings, boundary) => {
|
||||
const turf = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
|
||||
const pts = readings
|
||||
.filter(r => turf.booleanPointInPolygon(turf.point(r.loc), boundary, {ignoreBoundary: true}))
|
||||
.sort((a, b) => a.ts - b.ts)
|
||||
.map(r => r.loc);
|
||||
if (pts.length < 2) return 0;
|
||||
return Math.round(turf.length(turf.lineString(pts), {units: 'kilometers'}) * 100) / 100;
|
||||
};
|
||||
export default analyzeGPS;
|
||||
// Generation time: 5.576s
|
||||
// Result: PASS
|
||||
57
tests/12_mst_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
57
tests/12_mst_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,57 @@
|
||||
async function computeMST(tomlStr) {
|
||||
const [{ parse }, { default: Heap }, { default: table }] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/mnemonist/heap'),
|
||||
import('https://esm.sh/text-table'),
|
||||
]);
|
||||
|
||||
const { edges = [] } = parse(tomlStr);
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
const parent = new Map();
|
||||
const rank = new Map();
|
||||
|
||||
for (const e of edges) {
|
||||
heap.push(e);
|
||||
for (const n of [e.from, e.to]) {
|
||||
if (!parent.has(n)) {
|
||||
parent.set(n, n);
|
||||
rank.set(n, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const find = n => {
|
||||
while (parent.get(n) !== n) {
|
||||
parent.set(n, parent.get(parent.get(n)));
|
||||
n = parent.get(n);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
const union = (a, b) => {
|
||||
a = find(a);
|
||||
b = find(b);
|
||||
if (a === b) return false;
|
||||
if (rank.get(a) < rank.get(b)) [a, b] = [b, a];
|
||||
parent.set(b, a);
|
||||
if (rank.get(a) === rank.get(b)) rank.set(a, rank.get(a) + 1);
|
||||
return true;
|
||||
};
|
||||
|
||||
const rows = [['From', 'To', 'Weight']];
|
||||
const need = parent.size - 1;
|
||||
let totalWeight = 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(rows), totalWeight };
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 14.612s
|
||||
// Result: PASS
|
||||
24
tests/1_dijkstra/outputs/anthropic_claude-fable-5.js
Normal file
24
tests/1_dijkstra/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const findShortestPath = async (graph, start, end) => {
|
||||
const { default: PriorityQueue } = await import(
|
||||
'https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm'
|
||||
);
|
||||
const dist = { [start]: 0 };
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
|
||||
pq.queue([0, start]);
|
||||
while (pq.length) {
|
||||
const [d, node] = pq.dequeue();
|
||||
if (node === end) return d;
|
||||
if (d > (dist[node] ?? Infinity)) continue;
|
||||
for (const [next, w] of Object.entries(graph[node] ?? {})) {
|
||||
const nd = d + w;
|
||||
if (nd < (dist[next] ?? Infinity)) {
|
||||
dist[next] = nd;
|
||||
pq.queue([nd, next]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
};
|
||||
export default findShortestPath;
|
||||
// Generation time: 12.985s
|
||||
// Result: PASS
|
||||
18
tests/2_convex_hull/outputs/anthropic_claude-fable-5.js
Normal file
18
tests/2_convex_hull/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const findConvexHull = async points => {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
const pts = uniqWith(sortBy(points, ['x', 'y']), isEqual);
|
||||
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 = list => {
|
||||
const hull = [];
|
||||
for (const p of list) {
|
||||
while (hull.length > 1 && cross(hull.at(-2), hull.at(-1), p) <= 0) hull.pop();
|
||||
hull.push(p);
|
||||
}
|
||||
return hull.slice(0, -1);
|
||||
};
|
||||
return [...build(pts), ...build([...pts].reverse())];
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 14.047s
|
||||
// Result: PASS
|
||||
46
tests/3_signal_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
46
tests/3_signal_pipeline/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const analyzeSignal = async yamlStr => {
|
||||
const [yaml, math, ndarray, fft, DOMPurify] = (await Promise.all(
|
||||
['js-yaml', 'mathjs', 'ndarray', 'ndarray-fft', 'dompurify']
|
||||
.map(pkg => import(`https://esm.sh/${pkg}`))
|
||||
)).map(m => m.default ?? m);
|
||||
|
||||
const { sampleRate, duration, components } = yaml.load(yamlStr);
|
||||
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 peaks = [];
|
||||
for (let k = 0; k <= N / 2; k++) {
|
||||
const magnitude = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
|
||||
if (magnitude > 0.1) {
|
||||
peaks.push({
|
||||
frequencyHz: Math.round(k * sampleRate / N),
|
||||
magnitude: Math.round(magnitude * 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: 16.968s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,51 @@
|
||||
const load = name => import(`https://esm.sh/${name}`);
|
||||
|
||||
async function hexchain(tomlString) {
|
||||
const [
|
||||
{ parse },
|
||||
{ default: seedrandom },
|
||||
ss,
|
||||
{ default: Ajv },
|
||||
{ default: table },
|
||||
{ default: DOMPurify }
|
||||
] = await Promise.all(
|
||||
['smol-toml', 'seedrandom', 'simple-statistics', 'ajv', 'text-table', 'dompurify'].map(load)
|
||||
);
|
||||
|
||||
const config = parse(tomlString);
|
||||
const ajv = new Ajv();
|
||||
const schema = {
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
};
|
||||
|
||||
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 round6 = x => Math.round(x * 1e6) / 1e6;
|
||||
const [mean, stddev, median] = [ss.mean, ss.standardDeviation, ss.median].map(f => round6(f(nums)));
|
||||
|
||||
const ascii = table([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: DOMPurify.sanitize(`<pre class="stats">${ascii}</pre>`),
|
||||
count: config.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 14.324s
|
||||
// Result: PASS
|
||||
13
tests/5_markdown_parser/outputs/anthropic_claude-fable-5.js
Normal file
13
tests/5_markdown_parser/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,13 @@
|
||||
let markedPromise;
|
||||
|
||||
const loadMarked = () =>
|
||||
markedPromise ??= import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm');
|
||||
|
||||
async function parseMarkdown(markdown) {
|
||||
if (typeof markdown !== 'string') throw new TypeError('parseMarkdown expects a string');
|
||||
const { marked } = await loadMarked();
|
||||
return marked.parse(markdown, { gfm: true, async: true });
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 10.393s
|
||||
// Result: PASS
|
||||
23
tests/6_csv_processor/outputs/anthropic_claude-fable-5.js
Normal file
23
tests/6_csv_processor/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const processCSV = async (csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) => {
|
||||
const { default: Papa } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { data } = Papa.parse(csv.trim(), { header: true, skipEmptyLines: true });
|
||||
const groups = new Map();
|
||||
|
||||
for (const row of data) {
|
||||
if (row[filterColumn] != filterValue) continue;
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
const g = groups.get(key) ?? { sum: 0, count: 0 };
|
||||
g.sum += val;
|
||||
g.count++;
|
||||
groups.set(key, g);
|
||||
}
|
||||
|
||||
return [...groups].map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'sum' ? sum : operation === 'avg' ? sum / count : count
|
||||
}));
|
||||
};
|
||||
export default processCSV;
|
||||
// Generation time: 14.656s
|
||||
// Result: PASS
|
||||
42
tests/7_scheduler/outputs/anthropic_claude-fable-5.js
Normal file
42
tests/7_scheduler/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const findAvailableSlots = async (calendarA, calendarB, { durationMinutes, searchRange, workHours }) => {
|
||||
const { DateTime, Interval } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
|
||||
|
||||
const utc = s => DateTime.fromISO(s, { zone: 'utc' });
|
||||
const parseHM = s => s.split(':').map(Number);
|
||||
|
||||
const range = Interval.fromDateTimes(utc(searchRange.start), utc(searchRange.end));
|
||||
const busy = Interval.merge(
|
||||
[...calendarA, ...calendarB].map(({ start, end }) => Interval.fromDateTimes(utc(start), utc(end)))
|
||||
);
|
||||
const free = range.difference(...busy);
|
||||
|
||||
const [wsH, wsM] = parseHM(workHours.start);
|
||||
const [weH, weM] = parseHM(workHours.end);
|
||||
const slots = [];
|
||||
|
||||
for (const period of free) {
|
||||
let day = period.start.startOf('day');
|
||||
while (day < period.end) {
|
||||
const workWindow = Interval.fromDateTimes(
|
||||
day.set({ hour: wsH, minute: wsM }),
|
||||
day.set({ hour: weH, minute: weM })
|
||||
);
|
||||
const window = period.intersection(workWindow);
|
||||
if (window) {
|
||||
let cursor = window.start;
|
||||
let next = cursor.plus({ minutes: durationMinutes });
|
||||
while (next <= window.end) {
|
||||
slots.push({ start: cursor.toISO(), end: next.toISO() });
|
||||
cursor = next;
|
||||
next = cursor.plus({ minutes: durationMinutes });
|
||||
}
|
||||
}
|
||||
day = day.plus({ days: 1 });
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
};
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 20.786s
|
||||
// Result: PASS
|
||||
30
tests/8_json_validator/outputs/anthropic_claude-fable-5.js
Normal file
30
tests/8_json_validator/outputs/anthropic_claude-fable-5.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const validateJSON = (() => {
|
||||
let ajv;
|
||||
|
||||
const load = async () => {
|
||||
if (ajv) return ajv;
|
||||
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
|
||||
import('https://cdn.jsdelivr.net/npm/ajv@8/+esm'),
|
||||
import('https://cdn.jsdelivr.net/npm/ajv-formats@3/+esm')
|
||||
]);
|
||||
ajv = new Ajv({ allErrors: true, strict: false });
|
||||
addFormats(ajv);
|
||||
return ajv;
|
||||
};
|
||||
|
||||
const format = e =>
|
||||
`${e.instancePath || '/'} ${e.message}${e.params?.allowedValues ? `: ${e.params.allowedValues.join(', ')}` : ''}`;
|
||||
|
||||
return async (data, schema) => {
|
||||
try {
|
||||
const validator = (await load()).compile(schema);
|
||||
const valid = validator(data);
|
||||
return { valid, errors: valid ? [] : validator.errors.map(format) };
|
||||
} catch (err) {
|
||||
return { valid: false, errors: [`Schema error: ${err.message}`] };
|
||||
}
|
||||
};
|
||||
})();
|
||||
export default validateJSON;
|
||||
// Generation time: 13.342s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,21 @@
|
||||
async function createStreamVisualizer(src, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const data = [];
|
||||
let ema;
|
||||
for await (const { timestamp, value } of src) {
|
||||
ema = ema === undefined ? value : alpha * value + (1 - alpha) * ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
const x = d3.scaleLinear()
|
||||
.domain(data.length ? [data[0].timestamp, data[data.length - 1].timestamp] : [0, 1])
|
||||
.range([0, width]);
|
||||
const y = d3.scaleLinear().domain(yDomain).range([height, 0]);
|
||||
const path = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))(data) ?? '';
|
||||
return { data, path };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 6.412s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user