mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-04-27 11:52:12 +00:00
Docs: Update benchmark for anthropic/claude-opus-4.7 EFF:medium
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
const hashPassword = async (password, salt) => {
|
||||
const { scrypt } = await import('https://esm.sh/scrypt-js');
|
||||
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.662s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,12 @@
|
||||
const analyzeGPS = async (readings, boundary) => {
|
||||
const turf = await import('https://cdn.skypack.dev/@turf/turf');
|
||||
const valid = readings
|
||||
.filter(r => turf.booleanWithin(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));
|
||||
return Math.round(turf.length(line, { units: 'kilometers' }) * 100) / 100;
|
||||
};
|
||||
export default analyzeGPS;
|
||||
// Generation time: 3.035s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,62 @@
|
||||
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'),
|
||||
import('https://esm.sh/text-table')
|
||||
]);
|
||||
|
||||
const {edges = []} = parse(tomlString);
|
||||
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(), 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 sa = rank.get(ra), sb = rank.get(rb);
|
||||
if (sa < sb) parent.set(ra, rb);
|
||||
else if (sa > sb) parent.set(rb, ra);
|
||||
else { parent.set(rb, ra); rank.set(ra, sa + 1); }
|
||||
return true;
|
||||
};
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
const target = nodes.size - 1;
|
||||
|
||||
while (heap.size && mst.length < target) {
|
||||
const e = heap.pop();
|
||||
if (union(e.from, e.to)) {
|
||||
mst.push([e.from, e.to, String(e.weight)]);
|
||||
totalWeight += e.weight;
|
||||
}
|
||||
}
|
||||
|
||||
const table = textTable([['From', 'To', 'Weight'], ...mst]);
|
||||
return {table, totalWeight};
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 7.828s
|
||||
// Result: PASS
|
||||
@@ -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 n in graph) dist[n] = Infinity;
|
||||
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]) 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: 4.505s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,20 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = (await import('https://cdn.skypack.dev/lodash')).default;
|
||||
const pts = _.sortBy(_.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
if (pts.length < 2) return pts.slice();
|
||||
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);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
const lower = build(pts);
|
||||
const upper = build([...pts].reverse());
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 4.186s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,46 @@
|
||||
async function analyzeSignal(yamlStr) {
|
||||
const [yaml, math, ndarray, fft, DOMPurify] = (await Promise.all([
|
||||
import('https://esm.sh/js-yaml'),
|
||||
import('https://esm.sh/mathjs'),
|
||||
import('https://esm.sh/ndarray'),
|
||||
import('https://esm.sh/ndarray-fft'),
|
||||
import('https://esm.sh/dompurify')
|
||||
])).map(m => m.default ?? m);
|
||||
|
||||
const cfg = yaml.load(yamlStr);
|
||||
const N = cfg.sampleRate * cfg.duration;
|
||||
const signal = Array.from({ length: N }, (_, i) => {
|
||||
const t = i / cfg.sampleRate;
|
||||
return cfg.components.reduce(
|
||||
(s, c) => s + c.amplitude * math.sin(2 * math.pi * c.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 * cfg.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: 9.148s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,58 @@
|
||||
const hexchain = async toml => {
|
||||
const CDN = 'https://esm.sh/';
|
||||
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();
|
||||
const validate = ajv.compile(schema);
|
||||
if (!validate(config)) return {valid: false, errors: ajv.errorsText(validate.errors)};
|
||||
|
||||
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 tableStr = table([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
const sanitized = DOMPurify.sanitize(`<pre class="stats">${tableStr}</pre>`);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: {mean, stddev, median},
|
||||
table: sanitized,
|
||||
count: config.count
|
||||
};
|
||||
};
|
||||
export default hexchain;
|
||||
// Generation time: 8.530s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,7 @@
|
||||
const parseMarkdown = async md => {
|
||||
const { marked } = await import('https://cdn.jsdelivr.net/npm/marked/+esm');
|
||||
return marked.parse(md);
|
||||
};
|
||||
export default parseMarkdown;
|
||||
// Generation time: 1.391s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,23 @@
|
||||
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
|
||||
const { default: Papa } = await import('https://esm.sh/papaparse@5.4.1');
|
||||
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
|
||||
const groups = {};
|
||||
for (const row of data) {
|
||||
if (row[filterColumn] != filterValue) continue;
|
||||
const key = row[groupBy];
|
||||
const n = Number(row[aggregateColumn]);
|
||||
const val = Number.isFinite(n) ? n : 0;
|
||||
(groups[key] ??= { sum: 0, count: 0 });
|
||||
groups[key].sum += val;
|
||||
groups[key].count++;
|
||||
}
|
||||
const calc = {
|
||||
sum: g => g.sum,
|
||||
avg: g => g.sum / g.count,
|
||||
count: g => g.count,
|
||||
}[operation];
|
||||
return Object.entries(groups).map(([k, g]) => ({ [groupBy]: k, result: calc(g) }));
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 5.004s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,52 @@
|
||||
async function findAvailableSlots(cal1, cal2, { durationMinutes, searchRange, workHours }) {
|
||||
const { parseISO, addMinutes } = await import('https://cdn.skypack.dev/date-fns');
|
||||
const ms = s => parseISO(s).getTime();
|
||||
const iso = t => new Date(t).toISOString();
|
||||
const parseHM = t => {
|
||||
const [h, m] = t.split(':').map(Number);
|
||||
return (h * 60 + m) * 60000;
|
||||
};
|
||||
|
||||
const rs = ms(searchRange.start);
|
||||
const re = ms(searchRange.end);
|
||||
const durMs = durationMinutes * 60000;
|
||||
const whS = parseHM(workHours.start);
|
||||
const whE = parseHM(workHours.end);
|
||||
const DAY = 86400000;
|
||||
|
||||
const merged = [...cal1, ...cal2]
|
||||
.map(b => [ms(b.start), ms(b.end)])
|
||||
.filter(([s, e]) => e > rs && s < re)
|
||||
.map(([s, e]) => [Math.max(s, rs), Math.min(e, re)])
|
||||
.sort((a, b) => a[0] - b[0])
|
||||
.reduce((acc, [s, e]) => {
|
||||
const last = acc.at(-1);
|
||||
if (last && s <= last[1]) last[1] = Math.max(last[1], e);
|
||||
else acc.push([s, e]);
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const free = [];
|
||||
let cur = rs;
|
||||
for (const [s, e] of merged) {
|
||||
if (s > cur) free.push([cur, s]);
|
||||
cur = Math.max(cur, e);
|
||||
}
|
||||
if (cur < re) free.push([cur, re]);
|
||||
|
||||
const slots = [];
|
||||
for (const [fs, fe] of free) {
|
||||
for (let day = Math.floor(fs / DAY) * DAY; day < fe; day += DAY) {
|
||||
const s = Math.max(fs, day + whS);
|
||||
const e = Math.min(fe, day + whE);
|
||||
for (let t = s; t + durMs <= e; t = addMinutes(new Date(t), durationMinutes).getTime()) {
|
||||
slots.push({ start: iso(t), end: iso(t + durMs) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 28.829s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,13 @@
|
||||
const validateJSON = async (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);
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : validate.errors.map(e => `${e.instancePath || '/'} ${e.message}`)
|
||||
};
|
||||
};
|
||||
export default validateJSON;
|
||||
// Generation time: 2.748s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,31 @@
|
||||
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 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 = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.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.848s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user