-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.html
235 lines (215 loc) · 7.52 KB
/
benchmark.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="ja">
<head>
<title>Geodesic Distance Formulae Benchmark</title>
<meta charset="utf-8"/>
</head>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
"use strict";
let ERR_BIN_START = 0;
let ERR_BIN_END = 0;
let result = {};
let testdata = [];
let flag_graph_complete = false;
const worker = new Worker("benchmark_worker.js");
worker.onmessage = function(e){
document.getElementById("btn_benchmark").disabled = false;
document.getElementById("message").innerHTML = "";
ERR_BIN_START = Math.floor(Math.log10(e.data.distance_min));
ERR_BIN_END = Math.floor(Math.log10(e.data.distance_max));
testdata = e.data.testdata;
};
worker.postMessage({func: "loadTestData", args: []});
async function startBenchmark(){
document.getElementById("btn_benchmark").disabled = true;
document.getElementById("message").innerHTML = "executing benchmarks...";
result = await new Promise((resolve, reject) => {
worker.onmessage = function(e){
resolve(e.data);
};
worker.postMessage({
func: "startBenchmark",
args: [document.getElementById("input_benchmark_n").value - 0, result, ERR_BIN_START, ERR_BIN_END]
});
});
showResultTable(result);
document.getElementById("btn_benchmark").disabled = false;
document.getElementById("btn_drawgraph").disabled = false;
document.getElementById("message").innerHTML = "";
}
function showResultTable(){
const buf = []
let N = null;
buf.push("<table>");
buf.push("<table><tr><th>name</th><th>average time [ms]</th><th>std dev [ms]</th>");
for(let i = ERR_BIN_START; i <= ERR_BIN_END; i++){
if(i <= 0){
buf.push(`<th>${Math.pow(10,i).toPrecision(1)}m-</th>`);
}else{
buf.push(`<th>${Math.pow(10,i)}m-</th>`);
}
}
buf.push("</tr>");
for(const f in result){
buf.push("<tr><td class='center'>" + f + "</td>");
const avg = result[f].times.reduce((i, a) => i + a) / result[f].times.length;
const stddev = Math.sqrt(result[f].times.reduce((i, a) => i + (a - avg) ** 2, 0) / result[f].times.length);
buf.push("<td class='right'>" + avg.toFixed(2) + "</td>");
buf.push("<td class='right'>" + stddev.toFixed(2) + "</td>");
for(let i = 0; i <= ERR_BIN_END - ERR_BIN_START; i++){
if(result[f].errors.error_rel[i]){
buf.push("<td>" + result[f].errors.error_rel[i].toExponential(3) + "</td>");
}else{
buf.push("<td></td>");
}
}
buf.push("</tr>");
N = N || result[f].times.length;
}
buf.push("</table>");
buf.unshift(`<p>Calculation Time (N=${N}) and Relative Error</p>`);
document.getElementById("result").innerHTML = buf.join("");
}
async function showResultGraph(){
const labels = [];
const datasets = [];
const colors = ["#3f3d99", "#993d70", "#998b3d", "#3d9955", "#3d5a99", "#993d8f", "#996c3d", "#43993d", "#3d7899", "#833d99", "#994e3d", "#61993d"];
const shapes = ["rect", "triangle", "rectRot"];
if(flag_graph_complete){
return;
}
document.getElementById("message").innerHTML = "drawing graph...";
setTimeout(() => {
for(let i = ERR_BIN_START; i <= ERR_BIN_END; i++){
if(i <= 0){
labels.push(Math.pow(10,i));
}else{
labels.push(Math.pow(10,i));
}
}
let j = 0;
for(const f in result){
const dataset = {};
dataset.label = f;
dataset.backgroundColor = colors[j % colors.length];
dataset.pointStyle = shapes[Math.floor(j / 4) % shapes.length];
dataset.borderColor = dataset.backgroundColor;
dataset.data = [];
for(let i = 0; i < testdata.length; i += 1){
dataset.data.push([
testdata[i][6],
(result[f].dist[i] / testdata[i][6]) - 1
]);
}
j++;
datasets.push(dataset);
}
const chart = new Chart(document.getElementById("chart"), {
type: "scatter",
data: {
labels: labels,
datasets: datasets
},
options: {
plugins: {
tooltip: {
enabled: false
},
legend: {
labels: {
usePointStyle: true
}
}
},
scales: {
x: {
display: true,
type: "logarithmic",
title: {
display: true,
text: "True Distance [m]"
}
},
y: {
display: true,
type: "logarithmic",
title: {
display: true,
text: "Relative Error"
},
min: 1e-16,
max: 1e1,
ticks: {
callback: (val, index) => {
if(val.toExponential(1).startsWith("1")){
return val.toExponential(1);
}else{
return "";
}
}
}
}
}
}
});
flag_graph_complete = true;
document.getElementById("message").innerHTML = "";
}, 0);
}
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4RTVKDCC9W"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-4RTVKDCC9W');
</script>
<style>
table {
border-collapse: collapse;
}
th, td {
padding: 2px;
border: 1px solid gray;
}
.left{
text-align: left;
}
.center{
text-align: center;
}
.right{
text-align: right;
}
</style>
<body>
<h1>Geodesic Distance Calculation Formulae Benchmark in JavaScript</h1>
<p>
Compare calculation speed and precision for geodesic ellipsoid distance calculation functions implemented in JavaScript.
</p>
<div>
Compared Formulae:
<ul>
<li>GeographicLib: the most accurate calculation library. <a href="https://geographiclib.sourceforge.io/">GeographicLib</a>
<li>Haversine: <a href="https://en.wikipedia.org/wiki/Great-circle_distance">Great-circle distance - Wikipedia</a>
<li>GSI: Used by GSI(Geospatial Information Authority of Japan) distance calculation service, based on Bowring's method, <a href="https://vldb.gsi.go.jp/sokuchi/surveycalc/surveycalc/algorithm/bl2st/bl2st.htm">距離と方位角の計算 計算式</a>
<li>Hubeny: Simplified version of hubeny's formula, <a href="https://www.koeki-prj.org/~yuuji/2017/gd2/06/distances.html">Calculating Distance between Two Points - #7 Game Design 2017</a>
<li>Hubeny4: Full version of hubeny's formula, <a href="https://amano-tec.com/apps/paceruler.html">歩測計 Pace Ruler - ASTI アマノ技研</a>
<li>Vincenty: <a href="https://en.wikipedia.org/wiki/Geographical_distance#Lambert's_formula_for_long_lines">Geographical distance - Wikipedia</a>
<li>Lambert: <a href="https://dl.ndl.go.jp/info:ndljp/pid/11000306">回転楕円体上の測地線及び航程線の算出について - 国立国会図書館デジタルコレクション</a>
<li>Andoyer-Lambert: <a href="https://web.archive.org/web/20160411010136/http://www2.nc-toyama.ac.jp/~mkawai/lecture/sailing/geodetic/geosail.html">測地線航海算法(Geodesic Sailing)</a>
<li>Andoyer-Lambert-Thomas: <a href="https://metacpan.org/pod/GIS::Distance::ALT">GIS::Distance::ALT - Andoyer-Lambert-Thomas distance calculations. - metacpan.org</a>
</ul>
</div>
<div>
N: <input id="input_benchmark_n" type="number" min="1" max="100" value="5">
<button id="btn_benchmark" onclick="startBenchmark()" disabled>Start Benchmark</button>
<button id="btn_drawgraph" onclick="showResultGraph()" disabled>Draw Graph</button>
<span id="message">loading...</span>
<div id="result"></div>
<div><canvas id="chart"></canvas></div>
</div>
</body>
</html>