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:
@@ -9,7 +9,7 @@ async function findConvexHull(points) {
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const buildHull = pts => {
|
||||
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) {
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
const findConvexHull = async (points) => {
|
||||
const { sortBy, uniqWith, isEqual } =
|
||||
await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js');
|
||||
const _ = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js');
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const pts = sortBy(uniqWith(points, isEqual), ['x', 'y']);
|
||||
|
||||
if (pts.length < 3) return pts;
|
||||
|
||||
const lower = [];
|
||||
for (const p of pts) {
|
||||
while (lower.length >= 2 && cross(lower.at(-2), lower.at(-1), p) <= 0) {
|
||||
lower.pop();
|
||||
}
|
||||
lower.push(p);
|
||||
const uniquePts = _.uniqWith(points, _.isEqual);
|
||||
if (uniquePts.length < 3) {
|
||||
return uniquePts;
|
||||
}
|
||||
|
||||
const upper = [];
|
||||
for (let i = pts.length - 1; i >= 0; i--) {
|
||||
const p = pts[i];
|
||||
while (upper.length >= 2 && cross(upper.at(-2), upper.at(-1), p) <= 0) {
|
||||
upper.pop();
|
||||
}
|
||||
upper.push(p);
|
||||
}
|
||||
const crossProduct = (o, a, b) =>
|
||||
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const sortedPts = _.sortBy(uniquePts, ['x', 'y']);
|
||||
|
||||
const buildHalfHull = (pts) =>
|
||||
pts.reduce((hull, p) => {
|
||||
while (hull.length >= 2 && crossProduct(hull.at(-2), hull.at(-1), p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
return hull;
|
||||
}, []);
|
||||
|
||||
const lower = buildHalfHull(sortedPts);
|
||||
const upper = buildHalfHull([...sortedPts].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
};
|
||||
|
||||
22
tests/2_convex_hull/outputs/google_gemini-3-pro-preview.js
Normal file
22
tests/2_convex_hull/outputs/google_gemini-3-pro-preview.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const findConvexHull = async (pts) => {
|
||||
const { default: _ } = await import('https://cdn.skypack.dev/lodash');
|
||||
|
||||
const P = _.sortBy(_.uniqWith(pts, _.isEqual), ['x', 'y']);
|
||||
const n = P.length, k = [], C = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
||||
|
||||
if (n < 3) return P;
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
while (k.length >= 2 && C(k[k.length - 2], k[k.length - 1], P[i]) <= 0) k.pop();
|
||||
k.push(P[i]);
|
||||
}
|
||||
|
||||
for (let i = n - 2, t = k.length + 1; i >= 0; i--) {
|
||||
while (k.length >= t && C(k[k.length - 2], k[k.length - 1], P[i]) <= 0) k.pop();
|
||||
k.push(P[i]);
|
||||
}
|
||||
|
||||
k.pop();
|
||||
return k;
|
||||
};
|
||||
export default findConvexHull;
|
||||
@@ -1,24 +1,19 @@
|
||||
async function findConvexHull(points) {
|
||||
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4/esm/lodash.js');
|
||||
|
||||
if (!points || points.length < 3) return [...(points || [])];
|
||||
|
||||
const pts = _.sortBy(_.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['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 = arr => {
|
||||
const h = [];
|
||||
for (const p of arr) {
|
||||
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
|
||||
h.push(p);
|
||||
}
|
||||
return h;
|
||||
};
|
||||
|
||||
const lower = build(pts);
|
||||
const upper = build([...pts].reverse());
|
||||
|
||||
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
||||
}
|
||||
const findConvexHull = async (pts) => {
|
||||
const { sortBy, uniqBy } = await import('https://esm.sh/lodash-es@4');
|
||||
const cross = (a, b, c) => (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
|
||||
const sorted = sortBy(uniqBy(pts, p => `${p.x},${p.y}`), ['x', 'y']);
|
||||
if (sorted.length < 3) return sorted;
|
||||
const lower = [], upper = [];
|
||||
for (const p of sorted) {
|
||||
while (lower.length > 1 && cross(lower[lower.length-2], lower[lower.length-1], p) <= 0) lower.pop();
|
||||
lower.push(p);
|
||||
}
|
||||
for (let i = sorted.length - 1; i >= 0; i--) {
|
||||
const p = sorted[i];
|
||||
while (upper.length > 1 && cross(upper[upper.length-2], upper[upper.length-1], p) <= 0) upper.pop();
|
||||
upper.push(p);
|
||||
}
|
||||
lower.pop(); upper.pop();
|
||||
return [...lower, ...upper];
|
||||
};
|
||||
export default findConvexHull;
|
||||
@@ -1,20 +0,0 @@
|
||||
export async function findConvexHull(p){
|
||||
const _=(await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js')).default
|
||||
p=_.uniqWith(p,_.isEqual)
|
||||
p=_.sortBy(p,['x','y'])
|
||||
const c=(a,b,d)=>(b.x-a.x)*(d.y-a.y)-(b.y-a.y)*(d.x-a.x)
|
||||
const h=[]
|
||||
for(const v of p){
|
||||
while(h.length>1&&c(h[h.length-2],h[h.length-1],v)<=0)h.pop()
|
||||
h.push(v)
|
||||
}
|
||||
const u=[]
|
||||
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)
|
||||
}
|
||||
h.pop()
|
||||
u.pop()
|
||||
return [...h,...u]
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,18 +1,21 @@
|
||||
async function findConvexHull(points) {
|
||||
const {sortBy, uniqWith} = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js')
|
||||
const ps = uniqWith(sortBy(points.map(({x, y}) => ({x: +x, y: +y})), ['x', 'y']), (a, b) => a.x === b.x && a.y === b.y)
|
||||
if (ps.length < 2) return ps
|
||||
const c = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
||||
const lower = []
|
||||
for (const p of ps) {
|
||||
while (lower.length > 1 && c(lower.at(-2), lower.at(-1), p) <= 0) lower.pop()
|
||||
lower.push(p)
|
||||
async function findConvexHull(points){
|
||||
const m=await import('https://cdn.skypack.dev/lodash?min')
|
||||
const _=m.default||m
|
||||
const pts=_.sortBy(_.uniqWith(points,(a,b)=>a.x===b.x&&a.y===b.y),['x','y'])
|
||||
if(pts.length<3)return pts.slice()
|
||||
const h=[]
|
||||
const c=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x)
|
||||
for(const p of pts){
|
||||
while(h.length>1&&c(h.at(-2),h.at(-1),p)<=0)h.pop()
|
||||
h.push(p)
|
||||
}
|
||||
const upper = []
|
||||
for (const p of [...ps].reverse()) {
|
||||
while (upper.length > 1 && c(upper.at(-2), upper.at(-1), p) <= 0) upper.pop()
|
||||
upper.push(p)
|
||||
const t=h.length+1
|
||||
for(let i=pts.length-2;i>=0;i--){
|
||||
const p=pts[i]
|
||||
while(h.length>=t&&c(h.at(-2),h.at(-1),p)<=0)h.pop()
|
||||
h.push(p)
|
||||
}
|
||||
return lower.slice(0, -1).concat(upper.slice(0, -1))
|
||||
h.pop()
|
||||
return h
|
||||
}
|
||||
export default findConvexHull;
|
||||
@@ -1,16 +0,0 @@
|
||||
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;
|
||||
@@ -1,19 +1,22 @@
|
||||
async function findConvexHull(pts){
|
||||
const _=(await import('https://esm.run/lodash@4.17.21')).default;
|
||||
let p=_.uniqBy(_.sortBy(pts,['x','y']),q=>[q.x,q.y]);
|
||||
if(p.length<=2)return p;
|
||||
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 q of p){
|
||||
while(lower.length>=2&&cross(lower[lower.length-2],lower[lower.length-1],q)<=0)lower.pop();
|
||||
lower.push(q);
|
||||
}
|
||||
let upper=[];
|
||||
let rp=[...p].reverse();
|
||||
for(let q of rp){
|
||||
while(upper.length>=2&&cross(upper[upper.length-2],upper[upper.length-1],q)<=0)upper.pop();
|
||||
upper.push(q);
|
||||
}
|
||||
return lower.slice(0,-1).concat(upper.slice(0,-1));
|
||||
async function findConvexHull(points){
|
||||
const{default:L}=await import('https://cdn.skypack.dev/lodash-es');
|
||||
const{sortBy,uniqBy}=L;
|
||||
let p=uniqBy(points,({x,y})=>`${x},${y}`);
|
||||
if(p.length<2)return p;
|
||||
p=sortBy(p,['x','y']);
|
||||
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
|
||||
let l=[];
|
||||
for(let i=0;i<p.length;i++){
|
||||
let pt=p[i];
|
||||
while(l.length>=2&&cross(l[l.length-2],l[l.length-1],pt)<=0)l.pop();
|
||||
l.push(pt);
|
||||
}
|
||||
let u=[];
|
||||
for(let i=p.length-1;i>=0;i--){
|
||||
let pt=p[i];
|
||||
while(u.length>=2&&cross(u[u.length-2],u[u.length-1],pt)<=0)u.pop();
|
||||
u.push(pt);
|
||||
}
|
||||
return[...l.slice(0,-1),...u.slice(0,-1)];
|
||||
}
|
||||
export default findConvexHull;
|
||||
Reference in New Issue
Block a user