forked from bgrins/javascript-astar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.js
More file actions
34 lines (29 loc) · 1.05 KB
/
benchmark.js
File metadata and controls
34 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$(function() {
var running = false;
$("#runall").click(function() {
if (running) {
return;
}
running = true;
var graph = new Graph(grid),
start = graph.grid[0][0],
end = graph.grid[140][140],
results = [],
times = 0;
for (var i = 0; i < 1000; i++) {
var startTime = performance ? performance.now() : new Date().getTime(),
result = astar.search(graph, start, end),
endTime = performance ? performance.now() : new Date().getTime();
times = times + (endTime - startTime);
results.push(
'<li>Found path with ' + result.length + ' steps. ' +
'Took ' + (endTime - startTime).toFixed(2) + ' milliseconds.</li>'
);
}
$("#graph").html(graph.toString());
$("#summary").html('Average time: ' + (times / 1000).toFixed(2) + 'ms');
$("#results").html(results.join(''));
running = false;
return false;
});
});