mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 16:47:55 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
|
||||
const dist = Object.keys(graph).reduce((acc, node) => ({ ...acc, [node]: Infinity }), {});
|
||||
dist[start] = 0;
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
|
||||
pq.queue([start, 0]);
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length) {
|
||||
const [node, d] = pq.dequeue();
|
||||
|
||||
if (visited.has(node)) continue;
|
||||
visited.add(node);
|
||||
|
||||
if (node === end) return d;
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[node] || {})) {
|
||||
const newDist = d + weight;
|
||||
if (newDist < dist[neighbor]) {
|
||||
dist[neighbor] = newDist;
|
||||
pq.queue([neighbor, newDist]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dist[end];
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,25 +1,28 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm');
|
||||
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
|
||||
const dist = { [start]: 0 };
|
||||
const pq = new PQ({ comparator: (a, b) => a[1] - b[1] });
|
||||
pq.queue([start, 0]);
|
||||
const distances = {};
|
||||
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 });
|
||||
|
||||
while (pq.length) {
|
||||
const [node, d] = pq.dequeue();
|
||||
const { node, dist } = pq.dequeue();
|
||||
|
||||
if (node === end) return d;
|
||||
if (d > (dist[node] ?? Infinity)) continue;
|
||||
if (node === end) return dist;
|
||||
if (dist > distances[node]) continue;
|
||||
|
||||
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]);
|
||||
for (const neighbor in graph[node]) {
|
||||
const newDist = dist + graph[node][neighbor];
|
||||
if (newDist < distances[neighbor]) {
|
||||
distances[neighbor] = newDist;
|
||||
pq.queue({ node: neighbor, dist: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
return distances[end];
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,31 +0,0 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const { default: PriorityQueue } = await import('https://cdn.skypack.dev/js-priority-queue');
|
||||
|
||||
const distances = Object.keys(graph).reduce((acc, node) => ({ ...acc, [node]: Infinity }), {});
|
||||
distances[start] = 0;
|
||||
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
|
||||
pq.queue({ node: start, dist: 0 });
|
||||
|
||||
const visited = new Set();
|
||||
|
||||
while (pq.length) {
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distances[end];
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,32 +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 dist = {};
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => dist[a] - dist[b] });
|
||||
|
||||
for (const vertex in graph) {
|
||||
dist[vertex] = Infinity;
|
||||
}
|
||||
dist[startNode] = 0;
|
||||
|
||||
pq.queue(startNode);
|
||||
|
||||
while (pq.length) {
|
||||
const u = pq.dequeue();
|
||||
|
||||
if (u === endNode) break;
|
||||
if (!graph[u] || dist[u] === Infinity) continue;
|
||||
|
||||
for (const v in graph[u]) {
|
||||
const newDist = dist[u] + graph[u][v];
|
||||
|
||||
if (newDist < dist[v]) {
|
||||
dist[v] = newDist;
|
||||
pq.queue(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dist[endNode] ?? Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
33
tests/1_dijkstra/outputs/google_gemini-2.5-pro.js
Normal file
33
tests/1_dijkstra/outputs/google_gemini-2.5-pro.js
Normal file
@@ -0,0 +1,33 @@
|
||||
async function findShortestPath(graph, startNode, endNode) {
|
||||
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
|
||||
|
||||
const distances = { [startNode]: 0 };
|
||||
const queue = new PriorityQueue({ comparator: (a, b) => a.priority - b.priority });
|
||||
|
||||
queue.queue({ node: startNode, priority: 0 });
|
||||
|
||||
while (queue.length) {
|
||||
const { node: currentNode, priority: currentDist } = queue.dequeue();
|
||||
|
||||
if (currentDist > (distances[currentNode] ?? Infinity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentNode === endNode) {
|
||||
return currentDist;
|
||||
}
|
||||
|
||||
for (const neighbor in graph[currentNode] || {}) {
|
||||
const weight = graph[currentNode][neighbor];
|
||||
const newDist = currentDist + weight;
|
||||
|
||||
if (newDist < (distances[neighbor] ?? Infinity)) {
|
||||
distances[neighbor] = newDist;
|
||||
queue.queue({ node: neighbor, priority: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,29 +0,0 @@
|
||||
let pq;
|
||||
const loadPQ=()=>pq||(pq=import('https://cdn.skypack.dev/js-priority-queue').then(m=>m.default));
|
||||
|
||||
async function findShortestPath(graph,start,end){
|
||||
const PQ=await loadPQ();
|
||||
if(start===end) return 0;
|
||||
if(!graph||typeof graph!=='object') return Infinity;
|
||||
const d=new Map([[start,0]]);
|
||||
const q=new PQ({comparator:(a,b)=>a[0]-b[0]});
|
||||
q.queue([0,start]);
|
||||
while(q.length){
|
||||
const [w,n]=q.dequeue();
|
||||
if(w>(d.get(n)??Infinity)) continue;
|
||||
if(n===end) return w;
|
||||
const edges=graph[n];
|
||||
if(!edges||typeof edges!=='object') continue;
|
||||
for(const k of Object.keys(edges)){
|
||||
const c=edges[k];
|
||||
if(typeof c!=='number'||c<0||!Number.isFinite(c)) continue;
|
||||
const nw=w+c;
|
||||
if(nw<(d.get(k)??Infinity)){
|
||||
d.set(k,nw);
|
||||
q.queue([nw,k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
19
tests/1_dijkstra/outputs/openai_gpt-5.1-codex.js
Normal file
19
tests/1_dijkstra/outputs/openai_gpt-5.1-codex.js
Normal file
@@ -0,0 +1,19 @@
|
||||
async function findShortestPath(g,s,e){
|
||||
const {default:Q}=await import('https://cdn.skypack.dev/js-priority-queue')
|
||||
const d={[s]:0},q=new Q({comparator:(a,b)=>a.w-b.w})
|
||||
q.queue({n:s,w:0})
|
||||
while(q.length){
|
||||
const {n,w}=q.dequeue()
|
||||
if(w>(d[n]??Infinity))continue
|
||||
if(n===e)return w
|
||||
for(const k in g[n]||{}){
|
||||
const nw=w+g[n][k]
|
||||
if(nw<(d[k]??Infinity)){
|
||||
d[k]=nw
|
||||
q.queue({n:k,w:nw})
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
@@ -1,30 +0,0 @@
|
||||
async function findShortestPath(g,s,e){
|
||||
const {default:PriorityQueue} = await import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/jsprioryqueue.min.js').catch(()=>({default:class{
|
||||
constructor(o){this.c=o.comparator||((a,b)=>a-b);this.q=[]}
|
||||
queue(v){this.q.push(v);this.q.sort(this.c)}
|
||||
dequeue(){return this.q.shift()}
|
||||
peek(){return this.q[0]}
|
||||
get length(){return this.q.length}
|
||||
}}));
|
||||
if(!g||!g[s]||!g[e])return Infinity;
|
||||
const d={},v={},pq=new PriorityQueue({comparator:(a,b)=>a.w-b.w});
|
||||
for(const n in g)d[n]=Infinity;
|
||||
d[s]=0;
|
||||
pq.queue({n:s,w:0});
|
||||
while(pq.length){
|
||||
const {n,w}=pq.dequeue();
|
||||
if(v[n])continue;
|
||||
v[n]=1;
|
||||
if(n===e)return w;
|
||||
const nb=g[n];
|
||||
for(const k in nb){
|
||||
const nw=w+nb[k];
|
||||
if(nw<d[k]){
|
||||
d[k]=nw;
|
||||
pq.queue({n:k,w:nw});
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity;
|
||||
}
|
||||
export default findShortestPath;
|
||||
Reference in New Issue
Block a user