mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const findConvexHull = async (points) => {
|
||||
async function findConvexHull(points) {
|
||||
const _ = (await import("https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js")).default;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
@@ -22,6 +22,11 @@ const findConvexHull = async (points) => {
|
||||
upper.push(p);
|
||||
}
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
};
|
||||
export default findConvexHull;
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
|
||||
return [...lower, ...upper];
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 5.506s
|
||||
// Result: PASS
|
||||
@@ -1,34 +1,28 @@
|
||||
async function findConvexHull(points) {
|
||||
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const findConvexHull = async (points) => {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
|
||||
if (points.length < 3) return points;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const sorted = sortBy(uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
const sorted = sortBy(uniqWith(points, isEqual), ['x', 'y']);
|
||||
|
||||
if (sorted.length < 3) return sorted;
|
||||
|
||||
const lower = [];
|
||||
for (const p of sorted) {
|
||||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0) {
|
||||
lower.pop();
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const buildHalf = (pts) => {
|
||||
const hull = [];
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
lower.push(p);
|
||||
}
|
||||
hull.pop();
|
||||
return hull;
|
||||
};
|
||||
|
||||
const upper = [];
|
||||
for (let i = sorted.length - 1; i >= 0; i--) {
|
||||
const p = sorted[i];
|
||||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0) {
|
||||
upper.pop();
|
||||
}
|
||||
upper.push(p);
|
||||
}
|
||||
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
|
||||
return lower.concat(upper);
|
||||
}
|
||||
export default findConvexHull;
|
||||
return [...buildHalf(sorted), ...buildHalf([...sorted].reverse())];
|
||||
};
|
||||
export default findConvexHull;
|
||||
// Generation time: 4.808s
|
||||
// Result: PASS
|
||||
@@ -1,29 +0,0 @@
|
||||
async const findConvexHull = async (points) => {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
|
||||
const cross = (p1, p2, p3) =>
|
||||
(p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
|
||||
|
||||
const sortedPoints = sortBy(uniqWith(points, isEqual), ['x', 'y']);
|
||||
|
||||
if (sortedPoints.length <= 3) {
|
||||
return sortedPoints;
|
||||
}
|
||||
|
||||
const buildHull = (pointSet) => {
|
||||
const hull = [];
|
||||
for (const p of pointSet) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = buildHull(sortedPoints);
|
||||
const upper = buildHull([...sortedPoints].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
};
|
||||
export default findConvexHull;
|
||||
@@ -1,20 +1,20 @@
|
||||
const findConvexHull = async (pts) => {
|
||||
const { sortBy: S, uniqWith: U, isEqual: E } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
|
||||
const p = S(U(pts, E), ['x', 'y'])
|
||||
if (p.length < 3) return p
|
||||
const X = (a, b, o) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
||||
const B = (list) => {
|
||||
const h = []
|
||||
for (const pt of list) {
|
||||
while (h.length >= 2 && X(h[h.length - 1], pt, h[h.length - 2]) <= 0) h.pop()
|
||||
h.push(pt)
|
||||
}
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
|
||||
const s = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y'])
|
||||
if (s.length < 3) return s
|
||||
|
||||
const cp = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||
const walk = (h, p) => {
|
||||
while (h.length >= 2 && cp(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop()
|
||||
h.push(p)
|
||||
return h
|
||||
}
|
||||
const l = B(p)
|
||||
const u = B(p.reverse())
|
||||
l.pop()
|
||||
u.pop()
|
||||
return l.concat(u)
|
||||
|
||||
const l = s.reduce(walk, [])
|
||||
const u = s.reduceRight(walk, [])
|
||||
|
||||
return [...l.slice(0, -1), ...u.slice(0, -1)]
|
||||
}
|
||||
export default findConvexHull;
|
||||
export default findConvexHull;
|
||||
// Generation time: 33.416s
|
||||
// Result: PASS
|
||||
@@ -1,18 +1,23 @@
|
||||
async function findConvexHull(pts) {
|
||||
if (!Array.isArray(pts)) return [];
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
|
||||
const points = _.sortBy(_.uniqWith(pts, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
if (points.length < 3) return points;
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const build = (h, p) => {
|
||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
};
|
||||
const lower = [], upper = [];
|
||||
for (const p of points) build(lower, p);
|
||||
for (let i = points.length; i--; ) build(upper, points[i]);
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
return lower.concat(upper);
|
||||
async function findConvexHull(p) {
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'),
|
||||
u = _.uniqWith(_.sortBy(p, 'x', 'y'), (a, b) => a.x === b.x && a.y === b.y);
|
||||
if (u.length < 3) return u;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x),
|
||||
build = (pts) => {
|
||||
const h = [];
|
||||
for (const q of pts) {
|
||||
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], q) <= 0) h.pop();
|
||||
h.push(q);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const l = build(u),
|
||||
r = build([...u].reverse());
|
||||
|
||||
return [...l.slice(0, -1), ...r.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
export default findConvexHull;
|
||||
// Generation time: 147.393s
|
||||
// Result: FAIL
|
||||
@@ -1,19 +1,19 @@
|
||||
async function findConvexHull(points) {
|
||||
const { uniqWith, isEqual, sortBy } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js')
|
||||
const pts = sortBy(uniqWith(points, isEqual), ['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 scan = (src, acc = []) => {
|
||||
src.forEach(p => {
|
||||
while (acc.length > 1 && cross(acc.at(-2), acc.at(-1), p) <= 0) acc.pop()
|
||||
acc.push(p)
|
||||
})
|
||||
return acc
|
||||
export async function findConvexHull(pts){
|
||||
const {default:_}=await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const p=_.orderBy(_.uniqWith(pts,(a,b)=>a.x===b.x&&a.y===b.y),['x','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 l=[],u=[];
|
||||
for(const v of p){
|
||||
while(l.length>1&&c(l[l.length-2],l[l.length-1],v)<=0)l.pop();
|
||||
l.push(v);
|
||||
}
|
||||
const lower = scan(pts)
|
||||
const upper = scan([...pts].reverse())
|
||||
lower.pop()
|
||||
upper.pop()
|
||||
return lower.concat(upper)
|
||||
for(const v of [...p].reverse()){
|
||||
while(u.length>1&&c(u[u.length-2],u[u.length-1],v)<=0)u.pop();
|
||||
u.push(v);
|
||||
}
|
||||
return l.slice(0,-1).concat(u.slice(0,-1));
|
||||
}
|
||||
export default findConvexHull;
|
||||
export default findConvexHull;
|
||||
// Generation time: 10.565s
|
||||
// Result: PASS
|
||||
@@ -1,38 +0,0 @@
|
||||
const findConvexHull = async points => {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.skypack.dev/lodash')
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
||||
|
||||
const preparePoints = pts => {
|
||||
const unique = uniqWith(pts, isEqual)
|
||||
return sortBy(unique, ['x', 'y'])
|
||||
}
|
||||
|
||||
const buildHull = pts => {
|
||||
const hull = []
|
||||
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop()
|
||||
}
|
||||
hull.push(p)
|
||||
}
|
||||
|
||||
const lowerHullSize = hull.length + 1
|
||||
for (let i = pts.length - 1; i >= 0; i--) {
|
||||
const p = pts[i]
|
||||
while (hull.length >= lowerHullSize && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop()
|
||||
}
|
||||
hull.push(p)
|
||||
}
|
||||
|
||||
hull.pop()
|
||||
return hull
|
||||
}
|
||||
|
||||
if (points.length < 3) return [...points]
|
||||
const prepared = preparePoints(points)
|
||||
return buildHull(prepared)
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,12 +0,0 @@
|
||||
async function findConvexHull(pts){
|
||||
const{ sortBy:s,uniqBy:u }=await import('https://cdn.skypack.dev/lodash');
|
||||
if(!pts?.length)return[];
|
||||
const p=u(s(pts,['x','y']),t=>`${t.x},${t.y}`);
|
||||
if(p.length<2)return p;
|
||||
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
let l=[];for(let t of p){while(l.length>1&&c(l[l.length-2],l[l.length-1],t)<=0)l.pop();l.push(t)}
|
||||
let r=[];for(let i=p.length-1;i>=0;i--){const t=p[i];while(r.length>1&&c(r[r.length-2],r[r.length-1],t)<=0)r.pop();r.push(t)}
|
||||
l.pop();r.pop();
|
||||
return[...l,...r];
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,19 +0,0 @@
|
||||
async function findConvexHull(pts) {
|
||||
const { sortBy, uniqBy } = await import('https://cdn.skypack.dev/lodash-es');
|
||||
const ps = uniqBy(pts, p => `${p.x},${p.y}`);
|
||||
if (ps.length < 2) return ps;
|
||||
const sorted = sortBy(ps, ['x', 'y']);
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
const build = (pnts) => {
|
||||
const h = [];
|
||||
for (let p of pnts) {
|
||||
while (h.length > 1 && cross(h[h.length - 2], h.at(-1), p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
const lower = build(sorted);
|
||||
const upper = build([...sorted].reverse());
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
28
tests/2_convex_hull/outputs/x-ai_grok-4.js
Normal file
28
tests/2_convex_hull/outputs/x-ai_grok-4.js
Normal file
@@ -0,0 +1,28 @@
|
||||
async function findConvexHull(points) {
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
|
||||
if (points.length <= 1) return points.slice();
|
||||
let pts = _.sortBy(_.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
|
||||
if (pts.length <= 1) return pts;
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
let lower = [];
|
||||
for (let p of pts) {
|
||||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0) {
|
||||
lower.pop();
|
||||
}
|
||||
lower.push(p);
|
||||
}
|
||||
let upper = [];
|
||||
for (let i = pts.length - 1; i >= 0; i--) {
|
||||
let p = pts[i];
|
||||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0) {
|
||||
upper.pop();
|
||||
}
|
||||
upper.push(p);
|
||||
}
|
||||
lower.pop();
|
||||
upper.pop();
|
||||
return lower.concat(upper);
|
||||
}
|
||||
export default findConvexHull;
|
||||
// Generation time: 60.720s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user