mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
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.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 pq = new PQ({ comparator: (a, b) => a.dist - b.dist });
|
||||
const pq = new PriorityQueue({ comparator: (a, b) => a.dist - b.dist });
|
||||
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;
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
async function findShortestPath(graph, start, end) {
|
||||
const findShortestPath = async (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 = Object.fromEntries(
|
||||
Object.keys(graph).map(node => [node, Infinity])
|
||||
Object.keys(graph).map(node => [node, 1 / 0])
|
||||
);
|
||||
distances[start] = 0;
|
||||
distances[startNode] = 0;
|
||||
|
||||
const pq = new PriorityQueue({
|
||||
comparator: (a, b) => distances[b] - distances[a]
|
||||
comparator: (a, b) => a.priority - b.priority
|
||||
});
|
||||
pq.queue(start);
|
||||
pq.queue({ node: startNode, priority: 0 });
|
||||
|
||||
while (pq.length) {
|
||||
const currentNode = pq.dequeue();
|
||||
const { node: u, priority: dist } = pq.dequeue();
|
||||
|
||||
if (currentNode === end) break;
|
||||
if (dist > distances[u]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!graph[currentNode]) continue;
|
||||
if (u === endNode) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const [neighbor, weight] of Object.entries(graph[currentNode])) {
|
||||
const newDist = distances[currentNode] + weight;
|
||||
|
||||
if (newDist < distances[neighbor]) {
|
||||
distances[neighbor] = newDist;
|
||||
pq.queue(neighbor);
|
||||
for (const [v, weight] of Object.entries(graph[u] ?? {})) {
|
||||
const newDist = distances[u] + weight;
|
||||
if (newDist < distances[v]) {
|
||||
distances[v] = newDist;
|
||||
pq.queue({ node: v, priority: newDist });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distances[end];
|
||||
}
|
||||
return distances[endNode];
|
||||
};
|
||||
export default findShortestPath;
|
||||
23
tests/1_dijkstra/outputs/openai_gpt-5.1-chat.js
Normal file
23
tests/1_dijkstra/outputs/openai_gpt-5.1-chat.js
Normal file
@@ -0,0 +1,23 @@
|
||||
async function findShortestPath(g,s,e){
|
||||
const {default:Q}=await import('https://cdn.jsdelivr.net/npm/js-priority-queue@latest/dist/priority-queue.min.js')
|
||||
const d={},v={}
|
||||
for(const k in g)d[k]=Infinity
|
||||
d[s]=0
|
||||
const q=new Q({comparator:(a,b)=>a[1]-b[1]})
|
||||
q.queue([s,0])
|
||||
while(q.length){
|
||||
const [n,w]=q.dequeue()
|
||||
if(v[n])continue
|
||||
v[n]=1
|
||||
if(n===e)return w
|
||||
for(const k in g[n]){
|
||||
const nw=w+g[n][k]
|
||||
if(nw<d[k]){
|
||||
d[k]=nw
|
||||
q.queue([k,nw])
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
23
tests/1_dijkstra/outputs/openai_gpt-5.1-codex.js
Normal file
23
tests/1_dijkstra/outputs/openai_gpt-5.1-codex.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const findShortestPath=async(g,s,t)=>{
|
||||
if(s===t)return 0
|
||||
const{default:PriorityQueue}=await import('https://cdn.skypack.dev/js-priority-queue')
|
||||
if(!g[s]||!g[t])return Infinity
|
||||
const seen=new Map([[s,0]])
|
||||
const pq=new PriorityQueue({comparator:(a,b)=>a[1]-b[1]})
|
||||
pq.queue([s,0])
|
||||
while(pq.length){
|
||||
const[n,d]=pq.dequeue()
|
||||
if(d>(seen.get(n)??Infinity))continue
|
||||
if(n===t)return d
|
||||
const nbrs=g[n]||{}
|
||||
for(const k in nbrs){
|
||||
const nd=d+nbrs[k]
|
||||
if(nd<(seen.get(k)??Infinity)){
|
||||
seen.set(k,nd)
|
||||
pq.queue([k,nd])
|
||||
}
|
||||
}
|
||||
}
|
||||
return Infinity
|
||||
}
|
||||
export default findShortestPath;
|
||||
Reference in New Issue
Block a user