mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import("https://esm.run/js-priority-queue");
|
||||
|
||||
const dist = {}, visited = new Set();
|
||||
|
||||
for (let n in graph) dist[n] = Infinity;
|
||||
dist[start] = 0;
|
||||
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.4.1/+esm');
|
||||
|
||||
const dist = { [start]: 0 };
|
||||
const visited = new Set();
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
|
||||
pq.queue([start, 0]);
|
||||
|
||||
while (pq.length) {
|
||||
@@ -17,16 +15,17 @@ async function findShortestPath(graph, start, end) {
|
||||
|
||||
if (node === end) return d;
|
||||
|
||||
for (let neighbor in graph[node] || {}) {
|
||||
if (visited.has(neighbor)) continue;
|
||||
const newDist = d + graph[node][neighbor];
|
||||
if (newDist < dist[neighbor]) {
|
||||
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
|
||||
const newDist = d + weight;
|
||||
if (newDist < (dist[neighbor] ?? Infinity)) {
|
||||
dist[neighbor] = newDist;
|
||||
pq.queue([neighbor, newDist]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dist[end] ?? Infinity;
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
export default findShortestPath;
|
||||
// Generation time: 4.850s
|
||||
// Result: FAIL
|
||||
@@ -1,31 +1,35 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm');
|
||||
|
||||
const distances = Object.keys(graph).reduce((acc, node) => ({ ...acc, [node]: Infinity }), {});
|
||||
distances[start] = 0;
|
||||
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
|
||||
const distances = {};
|
||||
const visited = new Set();
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
|
||||
|
||||
for (const node in graph) distances[node] = Infinity;
|
||||
distances[start] = 0;
|
||||
pq.queue({ node: start, dist: 0 });
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length) {
|
||||
while (pq.length > 0) {
|
||||
const { node, dist } = pq.dequeue();
|
||||
|
||||
if (visited.has(node)) continue;
|
||||
visited.add(node);
|
||||
|
||||
if (node === end) return dist;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
|
||||
const newDist = dist + weight;
|
||||
if (newDist < distances[neighbor]) {
|
||||
distances[neighbor] = newDist;
|
||||
pq.queue({ node: neighbor, dist: newDist });
|
||||
visited.add(node);
|
||||
|
||||
for (const neighbor in graph[node]) {
|
||||
if (!visited.has(neighbor)) {
|
||||
const newDist = dist + graph[node][neighbor];
|
||||
if (newDist < distances[neighbor]) {
|
||||
distances[neighbor] = newDist;
|
||||
pq.queue({ node: neighbor, dist: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distances[end];
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
export default findShortestPath;
|
||||
// Generation time: 4.029s
|
||||
// Result: PASS
|
||||
@@ -1,40 +0,0 @@
|
||||
async function findShortestPath(graph, startNode, endNode) {
|
||||
const { default: PriorityQueue } = await import(
|
||||
'https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/priority-queue.min.js'
|
||||
);
|
||||
|
||||
const distances = {};
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
|
||||
|
||||
for (const node in graph) {
|
||||
distances[node] = Infinity;
|
||||
}
|
||||
distances[startNode] = 0;
|
||||
|
||||
pq.queue({ node: startNode, priority: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const { node: currentNode, priority: currentPriority } = pq.dequeue();
|
||||
|
||||
if (currentPriority > distances[currentNode]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentNode === endNode) {
|
||||
return currentPriority;
|
||||
}
|
||||
|
||||
for (const neighbor in graph[currentNode]) {
|
||||
const weight = graph[currentNode][neighbor];
|
||||
const newDistance = currentPriority + weight;
|
||||
|
||||
if (newDistance < distances[neighbor]) {
|
||||
distances[neighbor] = newDistance;
|
||||
pq.queue({ node: neighbor, priority: newDistance });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,7 +1,8 @@
|
||||
const findShortestPath = async (g, s, e) => {
|
||||
const { default: Q } = await import('https://esm.sh/js-priority-queue')
|
||||
const q = new Q({ comparator: (a, b) => a.w - b.w })
|
||||
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm')
|
||||
const q = new PQ({ comparator: (a, b) => a.w - b.w })
|
||||
const d = { [s]: 0 }
|
||||
|
||||
q.queue({ n: s, w: 0 })
|
||||
|
||||
while (q.length) {
|
||||
@@ -9,14 +10,17 @@ const findShortestPath = async (g, s, e) => {
|
||||
if (n === e) return w
|
||||
if (w > (d[n] ?? Infinity)) continue
|
||||
|
||||
for (const v in g[n]) {
|
||||
const k = w + g[n][v]
|
||||
if (k < (d[v] ?? Infinity)) {
|
||||
d[v] = k
|
||||
q.queue({ n: v, w: k })
|
||||
for (const k in g[n] || {}) {
|
||||
const t = w + g[n][k]
|
||||
if (t < (d[k] ?? Infinity)) {
|
||||
d[k] = t
|
||||
q.queue({ n: k, w: t })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
export default findShortestPath;
|
||||
// Generation time: 30.290s
|
||||
// Result: PASS
|
||||
@@ -1,28 +1,27 @@
|
||||
export async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/index.min.js');
|
||||
|
||||
if (!graph[start] || !graph[end]) return Infinity;
|
||||
if (start === end) return 0;
|
||||
|
||||
const dist = { [start]: 0 };
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
|
||||
pq.queue([0, start]);
|
||||
|
||||
while (pq.length) {
|
||||
const [d, node] = pq.dequeue();
|
||||
|
||||
if (node === end) return d;
|
||||
if (d > (dist[node] ?? Infinity)) continue;
|
||||
|
||||
for (const [n, w] of Object.entries(graph[node] || {})) {
|
||||
const nd = d + w;
|
||||
if (nd < (dist[n] ?? Infinity)) {
|
||||
dist[n] = nd;
|
||||
pq.queue([nd, n]);
|
||||
let PQ;
|
||||
export async function findShortestPath(g, s, e) {
|
||||
if (!(s in g) || !(e in g)) return Infinity;
|
||||
if (!PQ) ({ default: PQ } = await import('https://cdn.skypack.dev/js-priority-queue@0.1.5'));
|
||||
const d = new Map([[s, 0]]);
|
||||
const q = new PQ({ comparator: (a, b) => a[1] - b[1] });
|
||||
const v = new Set();
|
||||
q.queue([s, 0]);
|
||||
while (q.length) {
|
||||
const [n, c] = q.dequeue();
|
||||
if (n === e) return c;
|
||||
if (v.has(n)) continue;
|
||||
v.add(n);
|
||||
if (c > (d.get(n) ?? Infinity)) continue;
|
||||
for (const [p, w] of Object.entries(g[n] || {})) {
|
||||
const t = c + w;
|
||||
if (t < (d.get(p) ?? Infinity)) {
|
||||
d.set(p, t);
|
||||
q.queue([p, t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
return d.get(e) ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
export default findShortestPath;
|
||||
// Generation time: 95.484s
|
||||
// Result: PASS
|
||||
@@ -1,30 +1,24 @@
|
||||
let pqPromise
|
||||
const getPQ=()=>pqPromise??=import('https://cdn.jsdelivr.net/npm/js-priority-queue@latest/+esm')
|
||||
|
||||
async function findShortestPath(g,s,t){
|
||||
if(!g||!(s in g)||!(t in g)) return Infinity
|
||||
if(s===t) return 0
|
||||
const {default:PriorityQueue}=await getPQ()
|
||||
const d={[s]:0}
|
||||
const seen=new Set
|
||||
const q=new PriorityQueue({comparator:(a,b)=>a[0]-b[0]})
|
||||
q.queue([0,s])
|
||||
while(q.length){
|
||||
const [w,n]=q.dequeue()
|
||||
if(seen.has(n)) continue
|
||||
seen.add(n)
|
||||
if(n===t) return w
|
||||
const edges=g[n]
|
||||
if(!edges) continue
|
||||
for(const k in edges){
|
||||
if(seen.has(k)) continue
|
||||
const nw=w+edges[k]
|
||||
if(nw<(d[k]??Infinity)){
|
||||
d[k]=nw
|
||||
q.queue([nw,k])
|
||||
export const findShortestPath=async(g,s,e)=>{
|
||||
const{default:Q}=await import('https://esm.sh/js-priority-queue')
|
||||
const d={},v=new Set(),q=new Q({comparator:(a,b)=>a[1]-b[1]})
|
||||
for(const k in g)d[k]=Infinity
|
||||
d[s]=0
|
||||
q.queue([s,0])
|
||||
while(q.length){
|
||||
const[n,w]=q.dequeue()
|
||||
if(v.has(n))continue
|
||||
if(n===e)return w
|
||||
v.add(n)
|
||||
for(const[nb,c]of Object.entries(g[n]||{})){
|
||||
const nw=w+c
|
||||
if(nw<d[nb]){
|
||||
d[nb]=nw
|
||||
q.queue([nb,nw])
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
export default findShortestPath;
|
||||
// Generation time: 9.436s
|
||||
// Result: PASS
|
||||
@@ -1,37 +0,0 @@
|
||||
const findShortestPath = async (graph, start, end) => {
|
||||
const { default: PriorityQueue } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@1.0.0/+esm')
|
||||
|
||||
if (!graph[start] || !graph[end]) return Infinity
|
||||
|
||||
const distances = Object.keys(graph).reduce((acc, node) => {
|
||||
acc[node] = node === start ? 0 : Infinity
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.distance - b.distance })
|
||||
pq.queue({ node: start, distance: 0 })
|
||||
|
||||
const visited = new Set()
|
||||
|
||||
while (pq.length) {
|
||||
const { node, distance } = pq.dequeue()
|
||||
|
||||
if (node === end) return distance
|
||||
if (visited.has(node)) continue
|
||||
|
||||
visited.add(node)
|
||||
|
||||
Object.entries(graph[node]).forEach(([neighbor, weight]) => {
|
||||
if (visited.has(neighbor)) return
|
||||
|
||||
const newDistance = distance + weight
|
||||
if (newDistance < distances[neighbor]) {
|
||||
distances[neighbor] = newDistance
|
||||
pq.queue({ node: neighbor, distance: newDistance })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,24 +0,0 @@
|
||||
async function findShortestPath(graph,start,end){
|
||||
const {PriorityQueue}=await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
if(start===end)return 0;
|
||||
const dist={};
|
||||
dist[start]=0;
|
||||
const pq=new PriorityQueue({comparator:(a,b)=>a.dist-b.dist});
|
||||
pq.queue({node:start,dist:0});
|
||||
while(!pq.isEmpty()){
|
||||
const u=pq.dequeue();
|
||||
if(u.dist>dist[u.node])continue;
|
||||
const neighbors=graph[u.node];
|
||||
if(!neighbors)continue;
|
||||
for(const v in neighbors){
|
||||
const w=neighbors[v];
|
||||
const alt=dist[u.node]+w;
|
||||
if(alt<(dist[v]??Infinity)){
|
||||
dist[v]=alt;
|
||||
pq.queue({node:v,dist:alt});
|
||||
}
|
||||
}
|
||||
}
|
||||
return dist[end]??Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,21 +0,0 @@
|
||||
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.d - b.d });
|
||||
const dist = {};
|
||||
dist[start] = 0;
|
||||
pq.queue({ node: start, d: 0 });
|
||||
while (!pq.isEmpty()) {
|
||||
const { node, d } = pq.dequeue();
|
||||
if (d > dist[node]) continue;
|
||||
if (node === end) return d;
|
||||
for (const [nei, w] of Object.entries(graph[node] || {})) {
|
||||
const alt = d + w;
|
||||
if (alt < (dist[nei] ?? Infinity)) {
|
||||
dist[nei] = alt;
|
||||
pq.queue({ node: nei, d: alt });
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
22
tests/1_dijkstra/outputs/x-ai_grok-4.js
Normal file
22
tests/1_dijkstra/outputs/x-ai_grok-4.js
Normal file
@@ -0,0 +1,22 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const PQ = (await import('https://unpkg.com/js-priority-queue@0.1.5')).default;
|
||||
const D = {};
|
||||
D[start] = 0;
|
||||
const q = new PQ({comparator: (a, b) => a.d - b.d});
|
||||
q.queue({n: start, d: 0});
|
||||
while (q.length) {
|
||||
let {n: u, d} = q.dequeue();
|
||||
if (d > D[u]) continue;
|
||||
for (let v in graph[u]) {
|
||||
let a = d + graph[u][v];
|
||||
if (a < (D[v] ?? Infinity)) {
|
||||
D[v] = a;
|
||||
q.queue({n: v, d: a});
|
||||
}
|
||||
}
|
||||
}
|
||||
return D[end] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
// Generation time: 82.003s
|
||||
// Result: FAIL
|
||||
Reference in New Issue
Block a user