mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-08-28 04:45:42 +00:00
Docs: Update benchmark for google/gemini-3.7-flash EFF:high
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export async function hashPassword(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 Array.from(hash, (b) => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 8.431s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,16 @@
|
||||
export async function analyzeGPS(readings, boundary) {
|
||||
const { booleanPointInPolygon, lineString, length } = await import('https://esm.sh/@turf/turf');
|
||||
|
||||
const pts = readings
|
||||
.filter(r => booleanPointInPolygon(r.loc, boundary))
|
||||
.sort((a, b) => a.ts - b.ts)
|
||||
.map(r => r.loc);
|
||||
|
||||
if (pts.length < 2) return 0;
|
||||
|
||||
const totalLength = length(lineString(pts), { units: 'kilometers' });
|
||||
return +totalLength.toFixed(2);
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 9.365s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,73 @@
|
||||
export async function computeMST(tomlString) {
|
||||
const [{ parse }, mnemonist, textTableMod] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/mnemonist/heap'),
|
||||
import('https://esm.sh/text-table')
|
||||
]);
|
||||
|
||||
const Heap = mnemonist.default ?? mnemonist.Heap ?? mnemonist;
|
||||
const textTable = textTableMod.default ?? textTableMod;
|
||||
|
||||
const { edges = [] } = parse(tomlString);
|
||||
const parent = new Map();
|
||||
const rank = new Map();
|
||||
|
||||
for (const { from, to } of edges) {
|
||||
if (!parent.has(from)) parent.set(from, from), rank.set(from, 0);
|
||||
if (!parent.has(to)) parent.set(to, to), rank.set(to, 0);
|
||||
}
|
||||
|
||||
const find = (n) => {
|
||||
let root = n;
|
||||
while (root !== parent.get(root)) root = parent.get(root);
|
||||
let curr = n;
|
||||
while (curr !== root) {
|
||||
const next = parent.get(curr);
|
||||
parent.set(curr, root);
|
||||
curr = next;
|
||||
}
|
||||
return root;
|
||||
};
|
||||
|
||||
const union = (u, v) => {
|
||||
let rootU = find(u);
|
||||
let rootV = find(v);
|
||||
if (rootU === rootV) return false;
|
||||
|
||||
const rankU = rank.get(rootU);
|
||||
const rankV = rank.get(rootV);
|
||||
if (rankU < rankV) [rootU, rootV] = [rootV, rootU];
|
||||
|
||||
parent.set(rootV, rootU);
|
||||
if (rankU === rankV) rank.set(rootU, rankU + 1);
|
||||
return true;
|
||||
};
|
||||
|
||||
const heap = new Heap((a, b) => a.weight - b.weight);
|
||||
for (const edge of edges) heap.push(edge);
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
const targetEdges = Math.max(0, parent.size - 1);
|
||||
|
||||
while (heap.size > 0 && mst.length < targetEdges) {
|
||||
const edge = heap.pop();
|
||||
if (union(edge.from, edge.to)) {
|
||||
mst.push(edge);
|
||||
totalWeight += edge.weight;
|
||||
}
|
||||
}
|
||||
|
||||
const rows = [
|
||||
['From', 'To', 'Weight'],
|
||||
...mst.map(({ from, to, weight }) => [from, to, String(weight)])
|
||||
];
|
||||
|
||||
return {
|
||||
table: textTable(rows),
|
||||
totalWeight
|
||||
};
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 18.013s
|
||||
// Result: PASS
|
||||
27
tests/1_dijkstra/outputs/google_gemini-3.7-flash EFF_high.js
Normal file
27
tests/1_dijkstra/outputs/google_gemini-3.7-flash EFF_high.js
Normal file
@@ -0,0 +1,27 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
|
||||
const 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 [adj, weight] of Object.entries(graph[node] ?? {})) {
|
||||
const total = cost + weight;
|
||||
if (total < (dist[adj] ?? Infinity)) {
|
||||
dist[adj] = total;
|
||||
pq.queue({ node: adj, cost: total });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 10.601s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,32 @@
|
||||
export async function findConvexHull(points) {
|
||||
if (!Array.isArray(points) || points.length <= 2) {
|
||||
return points ? [...points] : [];
|
||||
}
|
||||
|
||||
const { orderBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const pts = orderBy(uniqWith(points, isEqual), ['x', 'y']);
|
||||
|
||||
if (pts.length <= 2) return pts;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const chain = list =>
|
||||
list.reduce((hull, pt) => {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], pt) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(pt);
|
||||
return hull;
|
||||
}, []);
|
||||
|
||||
const lower = chain(pts);
|
||||
const upper = chain([...pts].reverse());
|
||||
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
|
||||
return lower.concat(upper);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 12.593s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,59 @@
|
||||
export async function analyzeSignal(yamlStr) {
|
||||
const [
|
||||
{ default: yaml },
|
||||
math,
|
||||
{ default: ndarray },
|
||||
{ default: fft },
|
||||
{ default: 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')
|
||||
]);
|
||||
|
||||
const { sampleRate, duration, components } = yaml.load(yamlStr);
|
||||
const N = sampleRate * duration;
|
||||
const signal = new Float64Array(N);
|
||||
|
||||
for (let i = 0; i < N; i++) {
|
||||
const t = i / sampleRate;
|
||||
signal[i] = components.reduce(
|
||||
(acc, { frequency, amplitude }) =>
|
||||
acc + 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 peaks = [];
|
||||
const halfN = N / 2;
|
||||
|
||||
for (let k = 0; k <= halfN; k++) {
|
||||
const mag = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / halfN;
|
||||
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 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: 16.083s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,56 @@
|
||||
export async function hexchain(tomlString) {
|
||||
const [smol, sr, ss, ajvMod, tt, dp] = await Promise.all(
|
||||
['smol-toml', 'seedrandom', 'simple-statistics', 'ajv', 'text-table', 'dompurify']
|
||||
.map(lib => import(`https://esm.sh/${lib}`))
|
||||
);
|
||||
|
||||
const parse = smol.parse || smol.default?.parse || smol.default;
|
||||
const seedrandom = sr.default || sr;
|
||||
const Ajv = ajvMod.default || ajvMod;
|
||||
const table = tt.default || tt;
|
||||
const DOMPurify = dp.default || dp;
|
||||
|
||||
const config = parse(tomlString);
|
||||
const ajv = new Ajv();
|
||||
|
||||
const valid = ajv.validate({
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
}, config);
|
||||
|
||||
if (!valid) {
|
||||
return { valid: false, errors: ajv.errorsText() };
|
||||
}
|
||||
|
||||
const rng = new seedrandom(config.seed);
|
||||
const data = Array.from({ length: config.count }, () => rng());
|
||||
|
||||
const mean = +ss.mean(data).toFixed(6);
|
||||
const stddev = +ss.standardDeviation(data).toFixed(6);
|
||||
const median = +ss.median(data).toFixed(6);
|
||||
|
||||
const tableStr = table([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
const sanitizedHTML = DOMPurify.sanitize(`<pre class="stats">${tableStr}</pre>`);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: config.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: sanitizedHTML,
|
||||
count: config.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 24.452s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,7 @@
|
||||
export async function parseMarkdown(markdown) {
|
||||
const { marked } = await import('https://esm.sh/marked');
|
||||
return marked.parse(markdown ?? '');
|
||||
}
|
||||
export default parseMarkdown;
|
||||
// Generation time: 6.155s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,25 @@
|
||||
export async function processCSV(csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
|
||||
const { parse } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
const { data } = parse(csvString, { header: true, skipEmptyLines: true });
|
||||
|
||||
const groups = new Map();
|
||||
|
||||
for (const row of data) {
|
||||
if (row[filterColumn] == filterValue) {
|
||||
const key = row[groupBy];
|
||||
const val = +row[aggregateColumn] || 0;
|
||||
const acc = groups.get(key) || { sum: 0, count: 0 };
|
||||
acc.sum += val;
|
||||
acc.count += 1;
|
||||
groups.set(key, acc);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(groups, ([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? count : operation === 'avg' ? sum / count : sum
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 12.695s
|
||||
// Result: FAIL
|
||||
@@ -0,0 +1,78 @@
|
||||
export async function findAvailableSlots(calendar1 = [], calendar2 = [], constraints) {
|
||||
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3.4.4/+esm');
|
||||
|
||||
const durMs = constraints.durationMinutes * 60000;
|
||||
if (!durMs || durMs <= 0) return [];
|
||||
|
||||
const rangeStart = DateTime.fromISO(constraints.searchRange.start, { zone: 'utc' }).toMillis();
|
||||
const rangeEnd = DateTime.fromISO(constraints.searchRange.end, { zone: 'utc' }).toMillis();
|
||||
if (rangeStart >= rangeEnd) return [];
|
||||
|
||||
const [whStartH, whStartM] = constraints.workHours.start.split(':').map(Number);
|
||||
const [whEndH, whEndM] = constraints.workHours.end.split(':').map(Number);
|
||||
|
||||
const busySlots = [...calendar1, ...calendar2]
|
||||
.map(slot => ({
|
||||
start: DateTime.fromISO(slot.start, { zone: 'utc' }).toMillis(),
|
||||
end: DateTime.fromISO(slot.end, { zone: 'utc' }).toMillis()
|
||||
}))
|
||||
.filter(slot => slot.end > slot.start && slot.end > rangeStart && slot.start < rangeEnd)
|
||||
.sort((a, b) => a.start - b.start);
|
||||
|
||||
const mergedBusy = busySlots.reduce((acc, curr) => {
|
||||
if (!acc.length || acc.at(-1).end < curr.start) {
|
||||
acc.push({ ...curr });
|
||||
} else {
|
||||
acc.at(-1).end = Math.max(acc.at(-1).end, curr.end);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const slots = [];
|
||||
const addSlots = (from, to) => {
|
||||
for (let time = from; time + durMs <= to; time += durMs) {
|
||||
slots.push({
|
||||
start: new Date(time).toISOString(),
|
||||
end: new Date(time + durMs).toISOString()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let dayCursor = DateTime.fromMillis(rangeStart, { zone: 'utc' }).startOf('day');
|
||||
const lastDay = DateTime.fromMillis(rangeEnd, { zone: 'utc' }).startOf('day');
|
||||
|
||||
while (dayCursor <= lastDay) {
|
||||
const workStart = dayCursor.set({ hour: whStartH, minute: whStartM, second: 0, millisecond: 0 }).toMillis();
|
||||
const workEnd = dayCursor.set({ hour: whEndH, minute: whEndM, second: 0, millisecond: 0 }).toMillis();
|
||||
|
||||
const winStart = Math.max(workStart, rangeStart);
|
||||
const winEnd = Math.min(workEnd, rangeEnd);
|
||||
|
||||
if (winStart < winEnd) {
|
||||
let cursor = winStart;
|
||||
|
||||
for (const busy of mergedBusy) {
|
||||
if (busy.end <= cursor) continue;
|
||||
if (busy.start >= winEnd) break;
|
||||
|
||||
if (busy.start > cursor) {
|
||||
addSlots(cursor, Math.min(busy.start, winEnd));
|
||||
}
|
||||
|
||||
cursor = Math.max(cursor, busy.end);
|
||||
if (cursor >= winEnd) break;
|
||||
}
|
||||
|
||||
if (cursor < winEnd) {
|
||||
addSlots(cursor, winEnd);
|
||||
}
|
||||
}
|
||||
|
||||
dayCursor = dayCursor.plus({ days: 1 });
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 32.042s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,14 @@
|
||||
export async function validateJSON(data, schema) {
|
||||
const Ajv = (await import('https://esm.sh/ajv@8')).default;
|
||||
const ajv = new Ajv({ allErrors: true, strict: false });
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = Boolean(validate(data));
|
||||
const errors = valid
|
||||
? []
|
||||
: (validate.errors || []).map(e => `${e.instancePath || '#'} ${e.message}`);
|
||||
|
||||
return { valid, errors };
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 8.566s
|
||||
// Result: PASS
|
||||
@@ -0,0 +1,25 @@
|
||||
export async function createStreamVisualizer(
|
||||
asyncIterable,
|
||||
{ maxPoints = Infinity, alpha = 0.5, width = 800, height = 400, yDomain = [0, 100] } = {}
|
||||
) {
|
||||
const { scaleLinear, line } = await import('d3');
|
||||
const data = [];
|
||||
let ema;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
ema = ema === undefined ? value : alpha * value + (1 - alpha) * ema;
|
||||
data.push({ timestamp, value, ema });
|
||||
if (data.length > maxPoints) data.shift();
|
||||
}
|
||||
|
||||
if (!data.length) return { data, path: '' };
|
||||
|
||||
const x = scaleLinear().domain([data[0].timestamp, data.at(-1).timestamp]).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: 11.140s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user