mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-06-07 20:12:13 +00:00
Docs: Update benchmark for google/gemini-3.5-flash
This commit is contained in:
9
tests/10_scrypt_hash/outputs/google_gemini-3.5-flash.js
Normal file
9
tests/10_scrypt_hash/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,9 @@
|
||||
async function hashPassword(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 Array.from(hash, b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
export default hashPassword;
|
||||
// Generation time: 7.593s
|
||||
// Result: PASS
|
||||
15
tests/11_geospatial/outputs/google_gemini-3.5-flash.js
Normal file
15
tests/11_geospatial/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export async function analyzeGPS(readings, boundary) {
|
||||
const { booleanPointInPolygon: inPoly, point, lineString, length } =
|
||||
await import('https://cdn.jsdelivr.net/npm/@turf/turf/+esm');
|
||||
|
||||
const pts = readings
|
||||
.filter(r => inPoly(point(r.loc), boundary))
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
|
||||
return pts.length < 2
|
||||
? 0
|
||||
: +length(lineString(pts.map(r => r.loc))).toFixed(2);
|
||||
}
|
||||
export default analyzeGPS;
|
||||
// Generation time: 8.770s
|
||||
// Result: PASS
|
||||
73
tests/12_mst_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
73
tests/12_mst_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,73 @@
|
||||
export async function computeMST(tomlStr) {
|
||||
const [toml, heapMod, tableMod] = await Promise.all([
|
||||
import('https://esm.sh/smol-toml'),
|
||||
import('https://esm.sh/mnemonist/heap'),
|
||||
import('https://esm.sh/text-table')
|
||||
]);
|
||||
|
||||
const parse = toml.parse;
|
||||
const Heap = heapMod.default || heapMod;
|
||||
const textTable = tableMod.default || tableMod;
|
||||
|
||||
const { edges } = parse(tomlStr);
|
||||
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 = {};
|
||||
const rank = {};
|
||||
|
||||
const find = (i) => {
|
||||
if (!(i in parent)) parent[i] = i;
|
||||
return parent[i] === i ? i : (parent[i] = find(parent[i]));
|
||||
};
|
||||
|
||||
const union = (i, j) => {
|
||||
const rootI = find(i);
|
||||
const rootJ = find(j);
|
||||
if (rootI !== rootJ) {
|
||||
const rI = rank[rootI] || 0;
|
||||
const rJ = rank[rootJ] || 0;
|
||||
if (rI < rJ) {
|
||||
parent[rootI] = rootJ;
|
||||
} else if (rI > rJ) {
|
||||
parent[rootJ] = rootI;
|
||||
} else {
|
||||
parent[rootJ] = rootI;
|
||||
rank[rootI] = rI + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const mst = [];
|
||||
let totalWeight = 0;
|
||||
const targetEdges = nodes.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(e => [e.from, e.to, String(e.weight)])
|
||||
];
|
||||
|
||||
return {
|
||||
table: textTable(rows),
|
||||
totalWeight
|
||||
};
|
||||
}
|
||||
export default computeMST;
|
||||
// Generation time: 17.195s
|
||||
// Result: PASS
|
||||
28
tests/1_dijkstra/outputs/google_gemini-3.5-flash.js
Normal file
28
tests/1_dijkstra/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue@0.1.5');
|
||||
|
||||
const dists = { [start]: 0 };
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
|
||||
|
||||
pq.queue({ node: start, dist: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const { node, dist } = pq.dequeue();
|
||||
|
||||
if (node === end) return dist;
|
||||
if (dist > (dists[node] ?? Infinity)) continue;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) {
|
||||
const nextDist = dist + weight;
|
||||
if (nextDist < (dists[neighbor] ?? Infinity)) {
|
||||
dists[neighbor] = nextDist;
|
||||
pq.queue({ node: neighbor, dist: nextDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 11.455s
|
||||
// Result: PASS
|
||||
27
tests/2_convex_hull/outputs/google_gemini-3.5-flash.js
Normal file
27
tests/2_convex_hull/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,27 @@
|
||||
export async function findConvexHull(points) {
|
||||
const { sortBy, uniqBy } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
|
||||
const pts = sortBy(uniqBy(points, ({ x, y }) => `${x},${y}`), ['x', 'y']);
|
||||
|
||||
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 = (arr) => {
|
||||
const hull = [];
|
||||
for (const p of arr) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = build(pts);
|
||||
const upper = build([...pts].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 14.861s
|
||||
// Result: PASS
|
||||
52
tests/3_signal_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
52
tests/3_signal_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,52 @@
|
||||
export async function analyzeSignal(yamlStr) {
|
||||
const [yamlMod, mathMod, ndarrayMod, fftMod, purifyMod] = 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 yaml = yamlMod.load || yamlMod.default;
|
||||
const { sin, pi, sqrt } = mathMod.default || mathMod;
|
||||
const ndarray = ndarrayMod.default || ndarrayMod;
|
||||
const fft = fftMod.default || fftMod;
|
||||
const DOMPurify = purifyMod.default || purifyMod;
|
||||
|
||||
const { sampleRate, duration, components } = yaml(yamlStr);
|
||||
const N = sampleRate * duration;
|
||||
|
||||
const signal = Array.from({ length: N }, (_, i) => {
|
||||
const t = i / sampleRate;
|
||||
return components.reduce((sum, { frequency, amplitude }) =>
|
||||
sum + amplitude * sin(2 * 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 = sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / halfN;
|
||||
if (mag > 0.1) {
|
||||
peaks.push({
|
||||
frequencyHz: Math.round((k * sampleRate) / N),
|
||||
magnitude: +mag.toFixed(2)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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 table = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`;
|
||||
const html = DOMPurify.sanitize(table);
|
||||
|
||||
return { peaks, html, signalLength: N };
|
||||
}
|
||||
export default analyzeSignal;
|
||||
// Generation time: 35.362s
|
||||
// Result: PASS
|
||||
49
tests/4_hexchain_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
49
tests/4_hexchain_pipeline/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export async function hexchain(tomlStr) {
|
||||
const [
|
||||
{ parse },
|
||||
{ default: Seed },
|
||||
{ mean: ssM, standardDeviation: ssS, median: ssMed },
|
||||
{ default: Ajv },
|
||||
{ default: tbl },
|
||||
{ default: pur }
|
||||
] = await Promise.all([
|
||||
'smol-toml', 'seedrandom', 'simple-statistics', 'ajv', 'text-table', 'dompurify'
|
||||
].map(n => import(`https://esm.sh/${n}`)));
|
||||
|
||||
const cfg = parse(tomlStr);
|
||||
const ajv = new Ajv();
|
||||
|
||||
if (!ajv.validate({
|
||||
type: 'object',
|
||||
required: ['seed', 'count', 'label'],
|
||||
properties: {
|
||||
seed: { type: 'string' },
|
||||
count: { type: 'integer', minimum: 1, maximum: 10000 },
|
||||
label: { type: 'string', minLength: 1 }
|
||||
}
|
||||
}, cfg)) {
|
||||
return { valid: false, errors: ajv.errorsText() };
|
||||
}
|
||||
|
||||
const rng = new Seed(cfg.seed);
|
||||
const nums = Array.from({ length: cfg.count }, () => rng());
|
||||
const [mean, stddev, median] = [ssM, ssS, ssMed].map(f => +f(nums).toFixed(6));
|
||||
|
||||
const tableStr = tbl([
|
||||
['Stat', 'Value'],
|
||||
['mean', String(mean)],
|
||||
['stddev', String(stddev)],
|
||||
['median', String(median)]
|
||||
]);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
label: cfg.label,
|
||||
stats: { mean, stddev, median },
|
||||
table: pur.sanitize(`<pre class="stats">${tableStr}</pre>`),
|
||||
count: cfg.count
|
||||
};
|
||||
}
|
||||
export default hexchain;
|
||||
// Generation time: 27.764s
|
||||
// Result: PASS
|
||||
12
tests/5_markdown_parser/outputs/google_gemini-3.5-flash.js
Normal file
12
tests/5_markdown_parser/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export const parseMarkdown = async (markdown) => {
|
||||
try {
|
||||
const { marked } = await import('https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js');
|
||||
return marked.parse(markdown || '');
|
||||
} catch (error) {
|
||||
console.error('Failed to parse Markdown:', error);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
export default parseMarkdown;
|
||||
// Generation time: 8.849s
|
||||
// Result: PASS
|
||||
24
tests/6_csv_processor/outputs/google_gemini-3.5-flash.js
Normal file
24
tests/6_csv_processor/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,24 @@
|
||||
export async function processCSV(csvString, config) {
|
||||
const { filterColumn, filterValue, groupBy, aggregateColumn, operation } = config;
|
||||
const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm');
|
||||
|
||||
const { data } = Papa.parse(csvString, { header: true, skipEmptyLines: true });
|
||||
const groups = {};
|
||||
|
||||
for (const row of data) {
|
||||
if (row[filterColumn] == filterValue) {
|
||||
const groupVal = row[groupBy];
|
||||
groups[groupVal] = groups[groupVal] || { sum: 0, count: 0 };
|
||||
groups[groupVal].sum += +row[aggregateColumn] || 0;
|
||||
groups[groupVal].count++;
|
||||
}
|
||||
}
|
||||
|
||||
return Object.entries(groups).map(([key, { sum, count }]) => ({
|
||||
[groupBy]: key,
|
||||
result: operation === 'count' ? count : operation === 'sum' ? sum : sum / count
|
||||
}));
|
||||
}
|
||||
export default processCSV;
|
||||
// Generation time: 23.400s
|
||||
// Result: PASS
|
||||
57
tests/7_scheduler/outputs/google_gemini-3.5-flash.js
Normal file
57
tests/7_scheduler/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,57 @@
|
||||
export async function findAvailableSlots(calendar1, calendar2, constraints) {
|
||||
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3.4.4/+esm');
|
||||
|
||||
const { durationMinutes: dur, searchRange, workHours } = constraints;
|
||||
const parse = s => DateTime.fromISO(s, { zone: 'utc' });
|
||||
const sStart = parse(searchRange.start);
|
||||
const sEnd = parse(searchRange.end);
|
||||
|
||||
const busy = [...calendar1, ...calendar2]
|
||||
.map(b => ({ start: parse(b.start), end: parse(b.end) }))
|
||||
.filter(b => b.end > sStart && b.start < sEnd)
|
||||
.sort((a, b) => a.start - b.start);
|
||||
|
||||
const merged = [];
|
||||
for (const b of busy) {
|
||||
const last = merged[merged.length - 1];
|
||||
if (!last || b.start > last.end) merged.push(b);
|
||||
else if (b.end > last.end) last.end = b.end;
|
||||
}
|
||||
|
||||
const [sh, sm] = workHours.start.split(':').map(Number);
|
||||
const [eh, em] = workHours.end.split(':').map(Number);
|
||||
const slots = [];
|
||||
|
||||
const addSlots = (from, to) => {
|
||||
while (from.plus({ minutes: dur }) <= to) {
|
||||
const next = from.plus({ minutes: dur });
|
||||
slots.push({ start: from.toISO(), end: next.toISO() });
|
||||
from = next;
|
||||
}
|
||||
};
|
||||
|
||||
let day = sStart.startOf('day');
|
||||
while (day <= sEnd) {
|
||||
const dStart = day.set({ hour: sh, minute: sm, second: 0, millisecond: 0 });
|
||||
const dEnd = day.set({ hour: eh, minute: em, second: 0, millisecond: 0 });
|
||||
const activeStart = sStart > dStart ? sStart : dStart;
|
||||
const activeEnd = sEnd < dEnd ? sEnd : dEnd;
|
||||
|
||||
if (activeStart < activeEnd) {
|
||||
let time = activeStart;
|
||||
for (const b of merged) {
|
||||
if (b.end <= time) continue;
|
||||
if (b.start >= activeEnd) break;
|
||||
if (b.start > time) addSlots(time, b.start);
|
||||
if (b.end > time) time = b.end;
|
||||
}
|
||||
if (time < activeEnd) addSlots(time, activeEnd);
|
||||
}
|
||||
day = day.plus({ days: 1 });
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
// Generation time: 23.364s
|
||||
// Result: PASS
|
||||
13
tests/8_json_validator/outputs/google_gemini-3.5-flash.js
Normal file
13
tests/8_json_validator/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export async function validateJSON(data, schema) {
|
||||
const { default: Ajv } = await import('https://cdn.jsdelivr.net/npm/ajv@8/+esm');
|
||||
const validate = new Ajv({ allErrors: true, strict: false }).compile(schema);
|
||||
const valid = validate(data);
|
||||
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : validate.errors.map(e => `${e.instancePath || 'root'} ${e.message}`)
|
||||
};
|
||||
}
|
||||
export default validateJSON;
|
||||
// Generation time: 6.256s
|
||||
// Result: PASS
|
||||
30
tests/9_stream_visualizer/outputs/google_gemini-3.5-flash.js
Normal file
30
tests/9_stream_visualizer/outputs/google_gemini-3.5-flash.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
|
||||
const d3 = await import('https://cdn.jsdelivr.net/npm/d3@7/+esm');
|
||||
const data = [];
|
||||
let ema = null;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
ema = ema === null ? 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 = d3.scaleLinear()
|
||||
.domain([data[0].timestamp, data[data.length - 1].timestamp])
|
||||
.range([0, width]);
|
||||
|
||||
const y = d3.scaleLinear()
|
||||
.domain(yDomain)
|
||||
.range([height, 0]);
|
||||
|
||||
const line = d3.line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema));
|
||||
|
||||
return { data, path: line(data) };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
// Generation time: 7.968s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user