mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
Docs: Update benchmark for openrouter/sherlock-dash-alpha
This commit is contained in:
20
tests/1_dijkstra/outputs/openrouter_sherlock-dash-alpha.js
Normal file
20
tests/1_dijkstra/outputs/openrouter_sherlock-dash-alpha.js
Normal file
@@ -0,0 +1,20 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
const dist = {}; Object.keys(graph).forEach(n => dist[n] = Infinity); dist[start] = 0;
|
||||
pq.queue([start, 0]);
|
||||
while (!pq.isEmpty()) {
|
||||
const [u, d] = pq.dequeue();
|
||||
if (u === end) return d;
|
||||
if (d > dist[u]) continue;
|
||||
for (const [v, w] of Object.entries(graph[u] || {})) {
|
||||
const nd = d + w;
|
||||
if (nd < dist[v]) {
|
||||
dist[v] = nd;
|
||||
pq.queue([v, nd]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -0,0 +1,16 @@
|
||||
async function findConvexHull(points) {
|
||||
const {_, default: _} = await import('https://cdn.skypack.dev/lodash-es');
|
||||
const pts = _([...new Set(points.map(p=>`${p.x},${p.y}`))].map(s=>s.split(',').map(Number)).map(([x,y])=>({x,y})));
|
||||
const ccw=(a,b,c)=> (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
|
||||
const build=(pts,low)=> {
|
||||
const hull=[];
|
||||
for(let p of pts){
|
||||
while(hull.length>1&&ccw(hull[hull.length-2],hull[hull.length-1],p)<=0) hull.pop();
|
||||
hull.push(p);
|
||||
}
|
||||
return hull.slice(0,low?hull.length:hull.length-1);
|
||||
};
|
||||
if(pts.length<3) return pts;
|
||||
return [...build(pts.sort((a,b)=>a.x-b.x||a.y-b.y),1),...build(pts.slice().reverse(),0)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
12
tests/3_lis/outputs/openrouter_sherlock-dash-alpha.js
Normal file
12
tests/3_lis/outputs/openrouter_sherlock-dash-alpha.js
Normal file
@@ -0,0 +1,12 @@
|
||||
async function findLISLength(arr) {
|
||||
const {bisectLeft} = await import('https://cdn.skypack.dev/d3-array');
|
||||
if(!arr.length) return 0;
|
||||
const tails = [];
|
||||
for(const x of arr) {
|
||||
const i = bisectLeft(tails, x);
|
||||
if(i === tails.length) tails.push(x);
|
||||
else tails[i] = x;
|
||||
}
|
||||
return tails.length;
|
||||
}
|
||||
export default findLISLength;
|
||||
@@ -0,0 +1,5 @@
|
||||
const calculateDeterminant=async m=>{
|
||||
const{math}=await import('https://cdn.jsdelivr.net/npm/mathjs@12.4.2/lib/browser/math.js');
|
||||
return math.det(m);
|
||||
};
|
||||
export default calculateDeterminant;
|
||||
@@ -0,0 +1,35 @@
|
||||
async function parseMarkdown(md) {
|
||||
const { default: marked } = await import('https://cdn.skypack.dev/marked@14.1.2');
|
||||
marked.use({
|
||||
breaks: true,
|
||||
gfm: true,
|
||||
async tokenize(src) {
|
||||
const tokens = marked.lexer(src);
|
||||
for (const token of tokens) {
|
||||
if (token.type === 'list') {
|
||||
token.ordered = token.ordered || false;
|
||||
token.loose = !!token.items.find(item => item.text.includes('\n'));
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
},
|
||||
renderer: {
|
||||
heading(text, level) { return `<h${level}>${text}</h${level}>`; },
|
||||
strong(text) { return `<strong>${text}</strong>`; },
|
||||
em(text) { return `<em>${text}</em>`; },
|
||||
codespan(text) { return `<code>${text}</code>`; },
|
||||
link(href, title, text) { return `<a href="${href}"${title ? ` title="${title}"` : ''}>${text}</a>`; },
|
||||
code(code, infostring) {
|
||||
const lang = (infostring || '').match(/^([a-z0-9]+)/i);
|
||||
return `<pre><code class="${lang ? `language-${lang[1]}` : ''}">${code}</code></pre>`;
|
||||
},
|
||||
list(body, ordered) {
|
||||
const type = ordered ? 'ol' : 'ul';
|
||||
return `<${type}>${body}</${type}>`;
|
||||
},
|
||||
blockquote(quote) { return `<blockquote>${quote}</blockquote>`; }
|
||||
}
|
||||
});
|
||||
return marked.parse(md);
|
||||
}
|
||||
export default parseMarkdown;
|
||||
@@ -0,0 +1,2 @@
|
||||
async function processCSV(csv,cfg){const{Papa}=await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js');const{groupBy,mean,sum}=await import('https://cdn.jsdelivr.net/npm/@jazzband/lodash-deep@1.1.3/lodash-deep.min.js');const{data,meta}=Papa.parse(csv,{header:!0});const rows=data.filter(r=>r[cfg.filterColumn]==cfg.filterValue);const num=(v)=>+v||0;const grouped=groupBy(rows,r=>r[cfg.groupBy]);return Object.entries(grouped).map(([k,v])=>({ [cfg.groupBy]:k,result:cfg.operation==='sum'?sum(v.map(r=>num(r[cfg.aggregateColumn]))):cfg.operation==='avg'?mean(v.map(r=>num(r[cfg.aggregateColumn]))):v.length}))}
|
||||
export default processCSV;
|
||||
67
tests/7_scheduler/outputs/openrouter_sherlock-dash-alpha.js
Normal file
67
tests/7_scheduler/outputs/openrouter_sherlock-dash-alpha.js
Normal file
@@ -0,0 +1,67 @@
|
||||
async function findAvailableSlots(cal1, cal2, {durationMinutes, searchRange, workHours}) {
|
||||
const {luxon: {DateTime, Interval}} = await import('https://cdn.skypack.dev/luxon');
|
||||
|
||||
const workStart = DateTime.fromFormat(workHours.start, 'HH:mm');
|
||||
const workEnd = DateTime.fromFormat(workHours.end, 'HH:mm');
|
||||
const searchStart = DateTime.fromISO(searchRange.start);
|
||||
const searchEnd = DateTime.fromISO(searchRange.end);
|
||||
const duration = Duration.fromObject({minutes: durationMinutes});
|
||||
|
||||
const parseCal = cal => cal.map(s => ({
|
||||
start: DateTime.fromISO(s.start),
|
||||
end: DateTime.fromISO(s.end)
|
||||
})).filter(s => s.start < s.end);
|
||||
|
||||
const mergeOverlaps = slots => slots
|
||||
.sort((a,b) => a.start - b.end)
|
||||
.reduce((merged, curr) => {
|
||||
const last = merged[merged.length - 1];
|
||||
if (!last || last.end < curr.start) return [...merged, curr];
|
||||
last.end = Math.max(last.end, curr.end);
|
||||
return merged;
|
||||
}, []);
|
||||
|
||||
const allBusy = mergeOverlaps([...parseCal(cal1), ...parseCal(cal2)]);
|
||||
const freePeriods = [
|
||||
{start: searchStart, end: allBusy[0]?.start || searchEnd},
|
||||
...allBusy.flatMap((b,i) =>
|
||||
i < allBusy.length - 1 && b.end < allBusy[i+1].start
|
||||
? [{start: b.end, end: allBusy[i+1].start}]
|
||||
: []
|
||||
),
|
||||
...(allBusy.at(-1)?.end && allBusy.at(-1).end < searchEnd
|
||||
? [{start: allBusy.at(-1).end, end: searchEnd}]
|
||||
: [])
|
||||
].filter(p => p.start < p.end);
|
||||
|
||||
const slots = [];
|
||||
for (const period of freePeriods) {
|
||||
const int = Interval.fromDateTimes(period.start, period.end);
|
||||
let curr = int.start;
|
||||
|
||||
while (curr.plus(duration) <= int.end) {
|
||||
const slotStart = curr;
|
||||
const slotEnd = curr.plus(duration);
|
||||
|
||||
const dayStart = slotStart.set({hour: workStart.hour, minute: workStart.minute, second: 0, millisecond: 0});
|
||||
const dayEnd = slotStart.set({hour: workEnd.hour, minute: workEnd.minute, second: 0, millisecond: 0});
|
||||
|
||||
if (Interval.fromDateTimes(slotStart, slotEnd).containedBy(
|
||||
Interval.fromDateTimes(
|
||||
Math.max(slotStart, dayStart),
|
||||
Math.min(slotEnd, dayEnd)
|
||||
)
|
||||
)) {
|
||||
slots.push({
|
||||
start: slotStart.toISO(),
|
||||
end: slotEnd.toISO()
|
||||
});
|
||||
}
|
||||
|
||||
curr = slotEnd;
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
export default findAvailableSlots;
|
||||
@@ -0,0 +1,13 @@
|
||||
async function validateJSON(data, schema) {
|
||||
const { default: Ajv } = await import('https://cdn.skypack.dev/ajv@8');
|
||||
const ajv = new Ajv({ allErrors: true, verbose: true });
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(data);
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : ajv.errors?.map(e =>
|
||||
`${e.instancePath || 'data'}: ${e.message} (${e.params?.type || e.schema})`
|
||||
) || []
|
||||
};
|
||||
}
|
||||
export default validateJSON;
|
||||
@@ -0,0 +1,26 @@
|
||||
async function createStreamVisualizer(asyncIterable, { maxPoints = 100, alpha = 0.3, width = 800, height = 400, yDomain = [-1, 1] } = {}) {
|
||||
const { select, scaleLinear, scaleTime, line } = await import('https://cdn.skypack.dev/d3@7');
|
||||
|
||||
let data = [], prevEma;
|
||||
|
||||
for await (const { timestamp, value } of asyncIterable) {
|
||||
const ema = prevEma === undefined ? value : alpha * value + (1 - alpha) * prevEma;
|
||||
prevEma = 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[data.length - 1].timestamp]).range([0, width]);
|
||||
const y = scaleLinear().domain(yDomain).range([height, 0]);
|
||||
|
||||
const lineGen = line()
|
||||
.x(d => x(d.timestamp))
|
||||
.y(d => y(d.ema))
|
||||
.curve(select.curveMonotoneX);
|
||||
|
||||
return { data, path: lineGen(data) };
|
||||
}
|
||||
export default createStreamVisualizer;
|
||||
Reference in New Issue
Block a user