Docs: Update benchmark for z-ai/glm-5.1

This commit is contained in:
github-actions[bot]
2026-04-07 18:55:08 +00:00
parent e331b73dae
commit e7b9bb1a9c
12 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
async function hashPassword(password, salt) {
const { scrypt } = await import('https://esm.sh/scrypt-js')
const e = new TextEncoder()
const h = await scrypt(e.encode(password), e.encode(salt), 1024, 8, 1, 32)
return [...h].map(b => b.toString(16).padStart(2, '0')).join('')
}
export default hashPassword;
// Generation time: 33.046s
// Result: PASS

View File

@@ -0,0 +1,10 @@
async function analyzeGPS(readings, boundary) {
const t = await import('https://esm.sh/@turf/turf')
const v = readings
.filter(r => t.booleanPointInPolygon(t.point(r.loc), boundary))
.sort((a, b) => a.ts - b.ts)
return v.length < 2 ? 0 : Math.round(t.length(t.lineString(v.map(r => r.loc))) * 100) / 100
}
export default analyzeGPS;
// Generation time: 54.397s
// Result: PASS

View File

@@ -0,0 +1,39 @@
const computeMST = async s => {
const [{ parse }, { Heap }, { default: tt }] = await Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/mnemonist'),
import('https://esm.sh/text-table')
])
const { edges } = parse(s)
const p = {}, r = {}
const find = x => p[x] === x ? x : (p[x] = find(p[x]))
const union = (a, b) => {
a = find(a); b = find(b)
if (a === b) return false
if (r[a] < r[b]) [a, b] = [b, a]
p[b] = a
if (r[a] === r[b]) r[a]++
return true
}
const h = new Heap((a, b) => a.weight - b.weight)
const n = new Set()
for (const e of edges) {
if (!(e.from in p)) { p[e.from] = e.from; r[e.from] = 0 }
if (!(e.to in p)) { p[e.to] = e.to; r[e.to] = 0 }
h.push(e)
n.add(e.from); n.add(e.to)
}
const m = []
let w = 0
while (m.length < n.size - 1 && h.size) {
const { from, to, weight } = h.pop()
if (union(from, to)) {
m.push([from, to, String(weight)])
w += weight
}
}
return { table: tt([['From', 'To', 'Weight'], ...m]), totalWeight: w }
}
export default computeMST;
// Generation time: 47.623s
// Result: PASS

View File

@@ -0,0 +1,22 @@
async function findShortestPath(g, s, e) {
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue/+esm');
const q = new PQ({ comparator: (a, b) => a[1] - b[1] });
const d = { [s]: 0 };
q.queue([s, 0]);
while (q.length) {
const [n, c] = q.dequeue();
if (n === e) return c;
if (c > (d[n] ?? 1/0)) continue;
for (const nb in g[n] || {}) {
const nd = c + g[n][nb];
if (nd < (d[nb] ?? 1/0)) {
d[nb] = nd;
q.queue([nb, nd]);
}
}
}
return d[e] ?? 1/0;
}
export default findShortestPath;
// Generation time: 39.949s
// Result: PASS

View File

@@ -0,0 +1,25 @@
const findConvexHull = async (pts) => {
const _ = await import("https://esm.run/lodash");
const p = _.uniqBy(_.sortBy(pts, ["x", "y"]), p => p.x + "," + p.y);
if (p.length < 3) return p;
const c = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const h = [];
for (const pt of p) {
while (h.length >= 2 && c(h.at(-2), h.at(-1), pt) <= 0) h.pop();
h.push(pt);
}
const l = h.length + 1;
for (let i = p.length - 2; i >= 0; i--) {
while (h.length >= l && c(h.at(-2), h.at(-1), p[i]) <= 0) h.pop();
h.push(p[i]);
}
h.pop();
return h;
};
export default findConvexHull;
// Generation time: 35.612s
// Result: FAIL

View File

@@ -0,0 +1,44 @@
const analyzeSignal = async (yamlStr) => {
const [yaml, math, ndarray, fft, DOMPurify] = await Promise.all([
import('https://esm.sh/js-yaml').then(m => m.default),
import('https://esm.sh/mathjs').then(m => m.default),
import('https://esm.sh/ndarray').then(m => m.default),
import('https://esm.sh/ndarray-fft').then(m => m.default),
import('https://esm.sh/dompurify').then(m => m.default)
])
const { sampleRate: sr, duration, components } = yaml.load(yamlStr)
const N = sr * duration
const signal = new Float64Array(N)
for (let i = 0; i < N; i++) {
const t = i / sr
signal[i] = components.reduce(
(s, { amplitude: a, frequency: f }) => s + a * math.sin(2 * math.pi * f * t), 0)
}
const re = ndarray(signal, [N])
const im = ndarray(new Float64Array(N), [N])
fft(1, re, im)
const peaks = []
for (let k = 0; k <= N / 2; k++) {
const mag = math.sqrt(re.get(k) ** 2 + im.get(k) ** 2) / (N / 2)
if (mag > 0.1)
peaks.push({
frequencyHz: Math.round(k * sr / N),
magnitude: Math.round(mag * 100) / 100
})
}
peaks.sort((a, b) => b.magnitude - a.magnitude)
const html = `<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${peaks
.map(p => `<tr><td>${p.frequencyHz}</td><td>${p.magnitude}</td></tr>`)
.join('')}</table>`
return { peaks, html: DOMPurify.sanitize(html), signalLength: N }
}
export default analyzeSignal;
// Generation time: 72.180s
// Result: FAIL

View File

@@ -0,0 +1,42 @@
async function hexchain(tomlStr) {
const [{ parse }, { default: seedrandom }, ss, { default: Ajv }, { default: table }, { default: DOMPurify }] = await Promise.all([
import('https://esm.sh/smol-toml'),
import('https://esm.sh/seedrandom'),
import('https://esm.sh/simple-statistics'),
import('https://esm.sh/ajv'),
import('https://esm.sh/text-table'),
import('https://esm.sh/dompurify')
])
const config = 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 }
}
}, config)) return { valid: false, errors: ajv.errorsText() }
const rng = new seedrandom(config.seed)
const nums = Array.from({ length: config.count }, () => rng())
const mean = +ss.mean(nums).toFixed(6)
const stddev = +ss.standardDeviation(nums).toFixed(6)
const median = +ss.median(nums).toFixed(6)
const tableStr = table([
['Stat', 'Value'],
['mean', String(mean)],
['stddev', String(stddev)],
['median', String(median)]
])
return {
valid: true,
label: config.label,
stats: { mean, stddev, median },
table: DOMPurify.sanitize(`<pre class="stats">${tableStr}</pre>`),
count: config.count
}
}
export default hexchain;
// Generation time: 101.900s
// Result: PASS

View File

@@ -0,0 +1,7 @@
async function parseMarkdown(m) {
const { marked } = await import('https://esm.sh/marked')
return marked.parse(m)
}
export default parseMarkdown;
// Generation time: 29.156s
// Result: PASS

View File

@@ -0,0 +1,12 @@
async function processCSV(csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) {
const { default: P } = await import("https://cdn.jsdelivr.net/npm/papaparse@5/+esm")
const rows = P.parse(csv, { header: true, skipEmptyLines: true }).data.filter(r => r[fc] == fv)
const groups = rows.reduce((a, r) => ((a[r[gb]] ??= []).push(r), a), {})
return Object.entries(groups).map(([k, v]) => {
const sum = v.reduce((s, r) => s + (Number(r[ac]) || 0), 0)
return { [gb]: k, result: op == 'count' ? v.length : op == 'sum' ? sum : sum / v.length }
})
}
export default processCSV;
// Generation time: 46.157s
// Result: PASS

View File

@@ -0,0 +1,35 @@
const findAvailableSlots = async (c1, c2, cn) => {
const { DateTime: D } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
const f = s => D.fromISO(s, { zone: 'UTC' });
const m = t => { const [h, v] = t.split(':'); return +h * 60 + +v; };
const g = d => d.hour * 60 + d.minute;
const ws = m(cn.workHours.start), we = m(cn.workHours.end), dur = cn.durationMinutes;
let merged = [...c1, ...c2].map(x => ({ s: f(x.start), e: f(x.end) })).sort((a, b) => a.s - b.s);
let busy = [];
for (let b of merged) {
if (!busy.length || b.s > busy[busy.length - 1].e) busy.push(b);
else if (b.e > busy[busy.length - 1].e) busy[busy.length - 1].e = b.e;
}
let res = [], cur = f(cn.searchRange.start), end = f(cn.searchRange.end);
const nWs = d => d.plus({ days: 1 }).startOf('day').plus({ minutes: ws });
const proc = (fS, fE) => {
let c = fS;
if (g(c) < ws) c = c.startOf('day').plus({ minutes: ws });
while (c < fE) {
if (g(c) >= we) { c = nWs(c); continue; }
let e = c.plus({ minutes: dur });
if (e > fE) break;
if (g(e) <= we) { res.push({ start: c.toISO(), end: e.toISO() }); c = e; }
else { if (g(c) <= ws) break; c = nWs(c); }
}
};
for (let b of busy) {
if (cur < b.s) proc(cur, b.s);
if (cur < b.e) cur = b.e;
}
if (cur < end) proc(cur, end);
return res;
};
export default findAvailableSlots;
// Generation time: 134.745s
// Result: PASS

View File

@@ -0,0 +1,9 @@
async function validateJSON(json, schema) {
const { default: Ajv } = await import('https://esm.sh/ajv')
const ajv = new Ajv()
const valid = ajv.validate(schema, json)
return { valid, errors: valid ? [] : ajv.errors.map(e => e.message) }
}
export default validateJSON;
// Generation time: 28.047s
// Result: PASS

View File

@@ -0,0 +1,14 @@
async function createStreamVisualizer(s, {maxPoints: m, alpha: a, width: w, height: h, yDomain: [y0, y1]}) {
const {scaleLinear, line} = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm")
let d = [], e
for await (const {timestamp: t, value: v} of s) {
d.push({timestamp: t, value: v, ema: e = d.length ? a * v + (1 - a) * e : v})
if (d.length > m) d.shift()
}
const x = scaleLinear([d[0].timestamp, d.at(-1).timestamp], [0, w]),
y = scaleLinear([y0, y1], [h, 0])
return {data: d, path: line().x(p => x(p.timestamp)).y(p => y(p.ema))(d)}
}
export default createStreamVisualizer;
// Generation time: 93.516s
// Result: PASS