Docs: Update benchmark for google/gemini-3.1-flash-lite-preview

This commit is contained in:
github-actions[bot]
2026-03-03 22:42:09 +00:00
parent 5e98b8d911
commit 47ccd20b71
12 changed files with 293 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
async function hashPassword(pwd, salt) {
const { scrypt } = await import('https://esm.run/scrypt-js');
const enc = new TextEncoder();
const h = await scrypt(
enc.encode(pwd),
enc.encode(salt),
1024, 8, 1, 32
);
return Array.from(h)
.map(b => b.toString(16).padStart(2, '0'))
.join('');
}
export default hashPassword;
// Generation time: 1.026s
// Result: PASS

View File

@@ -0,0 +1,16 @@
async function analyzeGPS(readings, boundary) {
const { booleanPointInPolygon, lineString, length } = await import('https://cdn.skypack.dev/@turf/turf');
const valid = readings
.filter(r => booleanPointInPolygon(r.loc, boundary))
.sort((a, b) => a.ts - b.ts);
if (valid.length < 2) return 0;
const dist = length(lineString(valid.map(r => r.loc)), { units: 'kilometers' });
return +dist.toFixed(2);
}
export default analyzeGPS;
// Generation time: 1.377s
// Result: PASS

View File

@@ -0,0 +1,54 @@
async function computeMST(tomlStr) {
const [{ parse }, { Heap }, 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 nodes = new Set();
const heap = new Heap((a, b) => a.weight - b.weight);
edges.forEach(e => {
heap.push(e);
nodes.add(e.from);
nodes.add(e.to);
});
const parent = new Map([...nodes].map(n => [n, n]));
const rank = new Map([...nodes].map(n => [n, 0]));
const find = i => {
if (parent.get(i) !== i) parent.set(i, find(parent.get(i)));
return parent.get(i);
};
const union = (i, j) => {
let r1 = find(i), r2 = find(j);
if (r1 !== r2) {
rank.get(r1) < rank.get(r2) ? parent.set(r1, r2) : parent.set(r2, r1);
if (rank.get(r1) === rank.get(r2)) rank.set(r1, rank.get(r1) + 1);
return true;
}
return false;
};
const mst = [['From', 'To', 'Weight']];
let totalWeight = 0;
while (heap.size > 0 && mst.length < nodes.size) {
const { from, to, weight } = heap.pop();
if (union(from, to)) {
mst.push([from, to, String(weight)]);
totalWeight += weight;
}
}
return {
table: table.default(mst, { align: ['l', 'l', 'r'] }),
totalWeight
};
}
export default computeMST;
// Generation time: 1.865s
// Result: FAIL

View File

@@ -0,0 +1,25 @@
async function findShortestPath(graph, start, end) {
const { MinPriorityQueue } = await import('https://cdn.skypack.dev/@datastructures-js/priority-queue');
const dists = { [start]: 0 };
const pq = new MinPriorityQueue();
pq.enqueue(start, 0);
while (!pq.isEmpty()) {
const { element: u, priority: d } = pq.dequeue();
if (u === end) return d;
if (d > (dists[u] ?? Infinity)) continue;
for (const [v, weight] of Object.entries(graph[u] || {})) {
const alt = d + weight;
if (alt < (dists[v] ?? Infinity)) {
dists[v] = alt;
pq.enqueue(v, alt);
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 1.374s
// Result: FAIL

View File

@@ -0,0 +1,25 @@
async function findConvexHull(pts) {
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm');
const sorted = sortBy(uniqWith(pts, isEqual), ['x', 'y']);
const cross = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
const hull = [];
for (const p of sorted) {
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) hull.pop();
hull.push(p);
}
const lowerLen = hull.length;
for (let i = sorted.length - 2; i >= 0; i--) {
const p = sorted[i];
while (hull.length > lowerLen && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) hull.pop();
hull.push(p);
}
hull.pop();
return hull;
}
export default findConvexHull;
// Generation time: 1.322s
// Result: FAIL

View File

@@ -0,0 +1,14 @@
async function findLISLength(nums) {
const { bisectLeft } = await import('https://cdn.skypack.dev/d3-array');
const tails = [];
for (const x of nums) {
const i = bisectLeft(tails, x);
i === tails.length ? tails.push(x) : (tails[i] = x);
}
return tails.length;
}
export default findLISLength;
// Generation time: 0.903s
// Result: PASS

View File

@@ -0,0 +1,7 @@
async function renderTemplate(tmpl, data) {
const { compile } = await import('https://cdn.skypack.dev/handlebars');
return compile(tmpl)(data);
}
export default renderTemplate;
// Generation time: 1.302s
// Result: PASS

View File

@@ -0,0 +1,13 @@
async function parseMarkdown(md) {
const { marked } = await import('https://cdn.jsdelivr.net/npm/marked@12.0.0/+esm');
marked.setOptions({
gfm: true,
breaks: true
});
return marked.parse(md);
}
export default parseMarkdown;
// Generation time: 1.089s
// Result: PASS

View File

@@ -0,0 +1,23 @@
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
const { parse } = await import('https://cdn.skypack.dev/papaparse');
const { data: rows } = parse(csv, { header: true, dynamicTyping: true });
const filtered = rows.filter(r => r[filterColumn] == filterValue);
const groups = filtered.reduce((acc, row) => {
const key = row[groupBy];
acc[key] = acc[key] || [];
acc[key].push(Number(row[aggregateColumn]) || 0);
return acc;
}, {});
return Object.entries(groups).map(([key, vals]) => {
let res;
if (operation === 'sum') res = vals.reduce((a, b) => a + b, 0);
if (operation === 'count') res = vals.length;
if (operation === 'avg') res = vals.reduce((a, b) => a + b, 0) / vals.length;
return { [groupBy]: key, result: res };
});
}
export default processCSV;
// Generation time: 1.399s
// Result: PASS

View File

@@ -0,0 +1,53 @@
async function findAvailableSlots(cals, { durationMinutes: dur, searchRange: range, workHours: work }) {
const { DateTime, Interval } = await import('https://cdn.skypack.dev/luxon');
const parseOrNull = (date) => DateTime.fromISO(date, { zone: 'utc' });
const toUtcTime = (time, baseDate) => {
const [h, m] = time.split(':');
return baseDate.set({ hour: h, minute: m, second: 0, millisecond: 0 });
};
const rangeStart = parseOrNull(range.start);
const rangeEnd = parseOrNull(range.end);
const busyIntervals = [...cals.flat()]
.map(s => Interval.fromDateTimes(parseOrNull(s.start), parseOrNull(s.end)))
.filter(i => i.overlaps(Interval.fromDateTimes(rangeStart, rangeEnd)))
.sort((a, b) => a.start - b.start);
const merged = [];
for (const interval of busyIntervals) {
if (!merged.length || !merged[merged.length - 1].overlaps(interval)) merged.push(interval);
else merged[merged.length - 1] = merged[merged.length - 1].union(interval);
}
const freeSlots = [];
let current = rangeStart;
while (current < rangeEnd) {
const dayStart = toUtcTime(work.start, current);
const dayEnd = toUtcTime(work.end, current);
let pointer = current < dayStart ? dayStart : current;
const limit = current.plus({ days: 1 }).startOf('day') < rangeEnd
? dayEnd
: (rangeEnd < dayEnd ? rangeEnd : dayEnd);
while (pointer.plus({ minutes: dur }) <= limit) {
const slot = Interval.after(pointer, { minutes: dur });
if (!merged.some(m => m.overlaps(slot))) {
freeSlots.push({ start: slot.start.toISO(), end: slot.end.toISO() });
pointer = slot.end;
} else {
const nextBusy = merged.find(m => m.overlaps(slot));
pointer = nextBusy.end > pointer ? nextBusy.end : pointer.plus({ minutes: 1 });
}
}
current = current.plus({ days: 1 }).startOf('day');
}
return freeSlots;
}
export default findAvailableSlots;
// Generation time: 2.149s
// Result: FAIL

View File

@@ -0,0 +1,15 @@
async function validateJSON(data, schema) {
const { default: Ajv } = await import('https://esm.sh/ajv@8.12.0');
const ajv = new Ajv({ allErrors: true });
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: 1.098s
// Result: PASS

View File

@@ -0,0 +1,31 @@
async function createStreamVisualizer(stream, { maxPoints, alpha, width, height, yDomain }) {
const [{ scaleLinear, line, extent }] = await Promise.all([
import('https://cdn.skypack.dev/d3@7'),
]);
const data = [];
let ema = null;
for await (const { timestamp, value } of stream) {
ema = ema === null ? value : alpha * value + (1 - alpha) * ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
const xScale = scaleLinear()
.domain(extent(data, (d) => d.timestamp))
.range([0, width]);
const yScale = scaleLinear()
.domain(yDomain)
.range([height, 0]);
const path = line()
.x((d) => xScale(d.timestamp))
.y((d) => yScale(d.ema))(data);
return { data, path };
}
export default createStreamVisualizer;
// Generation time: 1.712s
// Result: PASS