mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-09-18 03:45:44 +00:00
Docs: Update benchmark for google/gemini-3.8-flash EFF:high
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
export async function hashPassword(password, salt) {
|
||||||
|
const { scrypt } = await import('https://esm.sh/scrypt-js@3.0.1');
|
||||||
|
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: 13.651s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export async function analyzeGPS(readings, boundary) {
|
||||||
|
const turf = await import('https://esm.sh/@turf/turf');
|
||||||
|
|
||||||
|
const pts = readings
|
||||||
|
.filter(r => turf.booleanPointInPolygon(r.loc, boundary, { ignoreBoundary: true }))
|
||||||
|
.sort((a, b) => a.ts - b.ts)
|
||||||
|
.map(r => r.loc);
|
||||||
|
|
||||||
|
return pts.length < 2
|
||||||
|
? 0
|
||||||
|
: +turf.length(turf.lineString(pts), { units: 'kilometers' }).toFixed(2);
|
||||||
|
}
|
||||||
|
export default analyzeGPS;
|
||||||
|
// Generation time: 24.485s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
class UnionFind {
|
||||||
|
p = new Map();
|
||||||
|
r = new Map();
|
||||||
|
|
||||||
|
constructor(elements) {
|
||||||
|
for (const el of elements) {
|
||||||
|
this.p.set(el, el);
|
||||||
|
this.r.set(el, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
find(i) {
|
||||||
|
if (this.p.get(i) !== i) this.p.set(i, this.find(this.p.get(i)));
|
||||||
|
return this.p.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
union(i, j) {
|
||||||
|
let [rootI, rootJ] = [this.find(i), this.find(j)];
|
||||||
|
if (rootI === rootJ) return false;
|
||||||
|
|
||||||
|
const [rankI, rankJ] = [this.r.get(rootI), this.r.get(rootJ)];
|
||||||
|
if (rankI < rankJ) [rootI, rootJ] = [rootJ, rootI];
|
||||||
|
this.p.set(rootJ, rootI);
|
||||||
|
if (rankI === rankJ) this.r.set(rootI, rankI + 1);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function computeMST(tomlStr) {
|
||||||
|
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(tomlStr);
|
||||||
|
const nodes = new Set();
|
||||||
|
const heap = new Heap((a, b) => Number(a.weight) - Number(b.weight));
|
||||||
|
|
||||||
|
for (const edge of edges) {
|
||||||
|
nodes.add(edge.from);
|
||||||
|
nodes.add(edge.to);
|
||||||
|
heap.push(edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uf = new UnionFind(nodes);
|
||||||
|
const mst = [];
|
||||||
|
let totalWeight = 0;
|
||||||
|
const targetEdges = Math.max(0, nodes.size - 1);
|
||||||
|
|
||||||
|
while (mst.length < targetEdges && heap.size > 0) {
|
||||||
|
const edge = heap.pop();
|
||||||
|
if (uf.union(edge.from, edge.to)) {
|
||||||
|
mst.push([edge.from, edge.to, String(edge.weight)]);
|
||||||
|
totalWeight += Number(edge.weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
table: table([['From', 'To', 'Weight'], ...mst]),
|
||||||
|
totalWeight
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default computeMST;
|
||||||
|
// Generation time: 31.116s
|
||||||
|
// Result: PASS
|
||||||
27
tests/1_dijkstra/outputs/google_gemini-3.8-flash EFF_high.js
Normal file
27
tests/1_dijkstra/outputs/google_gemini-3.8-flash EFF_high.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
export async function findShortestPath(graph, start, end) {
|
||||||
|
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
|
||||||
|
|
||||||
|
const dist = new Map([[start, 0]]);
|
||||||
|
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||||
|
pq.queue([start, 0]);
|
||||||
|
|
||||||
|
while (pq.length) {
|
||||||
|
const [node, cost] = pq.dequeue();
|
||||||
|
|
||||||
|
if (node === end) return cost;
|
||||||
|
if (cost > (dist.get(node) ?? Infinity)) continue;
|
||||||
|
|
||||||
|
for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) {
|
||||||
|
const nextCost = cost + weight;
|
||||||
|
if (nextCost < (dist.get(neighbor) ?? Infinity)) {
|
||||||
|
dist.set(neighbor, nextCost);
|
||||||
|
pq.queue([neighbor, nextCost]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Infinity;
|
||||||
|
}
|
||||||
|
export default findShortestPath;
|
||||||
|
// Generation time: 16.431s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export async function findConvexHull(points) {
|
||||||
|
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es/+esm');
|
||||||
|
|
||||||
|
const pts = sortBy(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 buildHull = (pList) => pList.reduce((hull, p) => {
|
||||||
|
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||||
|
hull.pop();
|
||||||
|
}
|
||||||
|
return hull.push(p), hull;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const lower = buildHull(pts);
|
||||||
|
const upper = buildHull([...pts].reverse());
|
||||||
|
|
||||||
|
return lower.slice(0, -1).concat(upper.slice(0, -1));
|
||||||
|
}
|
||||||
|
export default findConvexHull;
|
||||||
|
// Generation time: 25.877s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
export async function analyzeSignal(yamlString) {
|
||||||
|
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 { sampleRate, duration, components } = yaml.load(yamlString);
|
||||||
|
const N = sampleRate * duration;
|
||||||
|
const halfN = N / 2;
|
||||||
|
|
||||||
|
const signal = Float64Array.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(signal, [N]);
|
||||||
|
const imag = ndarray(new Float64Array(N), [N]);
|
||||||
|
fft(1, real, imag);
|
||||||
|
|
||||||
|
const peaks = [];
|
||||||
|
for (let k = 0; k <= halfN; k++) {
|
||||||
|
const magnitude = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / halfN;
|
||||||
|
if (magnitude > 0.1) {
|
||||||
|
peaks.push({ frequencyHz: (k * sampleRate) / N, magnitude });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
peaks.sort((a, b) => b.magnitude - a.magnitude);
|
||||||
|
for (const p of peaks) {
|
||||||
|
p.frequencyHz = Math.round(p.frequencyHz);
|
||||||
|
p.magnitude = +p.magnitude.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
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: 54.838s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
export async function hexchain(tomlStr) {
|
||||||
|
const cdn = 'https://esm.sh/';
|
||||||
|
const [
|
||||||
|
{ parse },
|
||||||
|
{ default: seedrandom },
|
||||||
|
{ mean: getMean, standardDeviation: getStd, median: getMedian },
|
||||||
|
{ default: Ajv },
|
||||||
|
{ default: textTable },
|
||||||
|
{ 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(tomlStr);
|
||||||
|
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 round = fn => +fn(nums).toFixed(6);
|
||||||
|
|
||||||
|
const mean = round(getMean);
|
||||||
|
const stddev = round(getStd);
|
||||||
|
const median = round(getMedian);
|
||||||
|
|
||||||
|
const tableStr = textTable([
|
||||||
|
['Stat', 'Value'],
|
||||||
|
['mean', String(mean)],
|
||||||
|
['stddev', String(stddev)],
|
||||||
|
['median', String(median)]
|
||||||
|
]);
|
||||||
|
|
||||||
|
const table = DOMPurify.sanitize(`<pre class="stats">${tableStr}</pre>`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
label: config.label,
|
||||||
|
stats: { mean, stddev, median },
|
||||||
|
table,
|
||||||
|
count: config.count
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default hexchain;
|
||||||
|
// Generation time: 57.013s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
let lib;
|
||||||
|
|
||||||
|
export async function parseMarkdown(text = '') {
|
||||||
|
lib ??= import('https://esm.sh/marked');
|
||||||
|
const { marked } = await lib;
|
||||||
|
return marked.parse(String(text));
|
||||||
|
}
|
||||||
|
export default parseMarkdown;
|
||||||
|
// Generation time: 15.759s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export async function processCSV(csvString, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
|
||||||
|
const Papa = (await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm')).default;
|
||||||
|
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
|
||||||
|
|
||||||
|
const groups = new Map();
|
||||||
|
for (const row of data) {
|
||||||
|
if (row[filterColumn] == filterValue) {
|
||||||
|
const key = row[groupBy];
|
||||||
|
const entry = groups.get(key) || { sum: 0, count: 0 };
|
||||||
|
entry.sum += Number(row[aggregateColumn]) || 0;
|
||||||
|
entry.count++;
|
||||||
|
groups.set(key, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(groups, ([key, { sum, count }]) => ({
|
||||||
|
[groupBy]: key,
|
||||||
|
result: operation === 'count' ? count : operation === 'avg' ? sum / count : sum
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
export default processCSV;
|
||||||
|
// Generation time: 82.511s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
export async function findAvailableSlots(cal1, cal2, constraints) {
|
||||||
|
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
|
||||||
|
const { durationMinutes, searchRange, workHours } = constraints;
|
||||||
|
const dur = durationMinutes * 60000;
|
||||||
|
const toUtc = s => DateTime.fromISO(s, { zone: 'utc' });
|
||||||
|
const [sH, sM] = workHours.start.split(':').map(Number);
|
||||||
|
const [eH, eM] = workHours.end.split(':').map(Number);
|
||||||
|
|
||||||
|
const rangeStart = toUtc(searchRange.start);
|
||||||
|
const rangeEnd = toUtc(searchRange.end);
|
||||||
|
const rStartMs = rangeStart.toMillis();
|
||||||
|
const rEndMs = rangeEnd.toMillis();
|
||||||
|
|
||||||
|
const busy = [...cal1, ...cal2]
|
||||||
|
.map(({ start, end }) => ({ s: toUtc(start).toMillis(), e: toUtc(end).toMillis() }))
|
||||||
|
.filter(b => b.s < b.e)
|
||||||
|
.sort((a, b) => a.s - b.s);
|
||||||
|
|
||||||
|
const mergedBusy = busy.reduce((acc, b) => {
|
||||||
|
const last = acc[acc.length - 1];
|
||||||
|
last && b.s <= last.e ? (last.e = Math.max(last.e, b.e)) : acc.push({ ...b });
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const slots = [];
|
||||||
|
const addSlots = (from, to) => {
|
||||||
|
for (let t = from; t + dur <= to; t += dur) {
|
||||||
|
slots.push({
|
||||||
|
start: DateTime.fromMillis(t, { zone: 'utc' }).toISO(),
|
||||||
|
end: DateTime.fromMillis(t + dur, { zone: 'utc' }).toISO()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let d = rangeStart.startOf('day'); d <= rangeEnd; d = d.plus({ days: 1 })) {
|
||||||
|
const wStart = Math.max(d.set({ hour: sH, minute: sM, second: 0, millisecond: 0 }).toMillis(), rStartMs);
|
||||||
|
const wEnd = Math.min(d.set({ hour: eH, minute: eM, second: 0, millisecond: 0 }).toMillis(), rEndMs);
|
||||||
|
|
||||||
|
if (wStart < wEnd) {
|
||||||
|
let cur = wStart;
|
||||||
|
for (const b of mergedBusy) {
|
||||||
|
if (b.e <= cur) continue;
|
||||||
|
if (b.s >= wEnd) break;
|
||||||
|
if (b.s > cur) addSlots(cur, Math.min(b.s, wEnd));
|
||||||
|
cur = Math.max(cur, b.e);
|
||||||
|
if (cur >= wEnd) break;
|
||||||
|
}
|
||||||
|
if (cur < wEnd) addSlots(cur, wEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return slots;
|
||||||
|
}
|
||||||
|
export default findAvailableSlots;
|
||||||
|
// Generation time: 71.113s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
export async function validateJSON(data, schema) {
|
||||||
|
try {
|
||||||
|
const { default: Ajv } = await import('https://esm.sh/ajv@8');
|
||||||
|
const validate = new Ajv({ allErrors: true, strict: false }).compile(schema);
|
||||||
|
const valid = !!validate(data);
|
||||||
|
|
||||||
|
return {
|
||||||
|
valid,
|
||||||
|
errors: valid ? [] : validate.errors.map(e => e.instancePath ? `${e.instancePath} ${e.message}` : e.message)
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
errors: [err.message]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default validateJSON;
|
||||||
|
// Generation time: 22.203s
|
||||||
|
// Result: PASS
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
export async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||||
|
const [d3, data] = await Promise.all([
|
||||||
|
import('d3'),
|
||||||
|
(async () => {
|
||||||
|
const buffer = [];
|
||||||
|
let ema;
|
||||||
|
for await (const { timestamp, value } of asyncIterable) {
|
||||||
|
ema = ema == null ? value : alpha * value + (1 - alpha) * ema;
|
||||||
|
buffer.push({ timestamp, value, ema });
|
||||||
|
if (buffer.length > maxPoints) buffer.shift();
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
})()
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!data.length) return { data, path: '' };
|
||||||
|
|
||||||
|
const x = d3.scaleLinear()
|
||||||
|
.domain([data[0].timestamp, data.at(-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: 21.189s
|
||||||
|
// Result: FAIL
|
||||||
Reference in New Issue
Block a user