-
Notifications
You must be signed in to change notification settings - Fork 64
/
benchmark.html
263 lines (236 loc) · 9.97 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Anchorme: Javascript library to detect links / URLs / Emails in text
and convert them to clickable HTML anchor links
</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="./assets/style.min.css" rel="stylesheet" />
<style>
.bench-bar {
background: #9e9e9e;
text-align: right;
padding: 5px;
font-size: 13px;
}
a {
cursor: pointer;
}
</style>
</head>
<body>
<!-- Main navigation
=========================================== -->
<header class="navbar navbar-static-top bs-docs-nav" id="top">
<div class="container">
<div class="navbar-header" role="banner">
<button
class="navbar-toggle"
type="button"
data-toggle="collapse"
data-target=".bs-navbar-collapse"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a
class="navbar-brand"
href="http://alexcorvi.github.io/anchorme.js/"
>Anchorme</a
>
</div>
<nav
class="collapse navbar-collapse bs-navbar-collapse"
role="navigation"
>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/alexcorvi/anchorme.js"
>View on GitHub</a
>
</li>
</ul>
</nav>
</div>
</header>
<!-- Header
=========================================== -->
<div
class="bs-docs-masthead"
id="content"
style="background: linear-gradient(135deg, #673ab7, #3f51b5);"
>
<div class="container">
<h1 class="home-title">Anchorme</h1>
<p class="lead" style="font-size: 18px; margin-top: 25px;">
Benchmark
</p>
</div>
</div>
<div class="container bs-docs-container">
<div class="row">
<div class="col-md-3">
<div>
<a onclick="placeShortText();run();">Test short text</a
><br />
<a onclick="placeMediumText();run();"
>Test medium text</a
><br />
<a onclick="placeLongText();run();">Test long text</a
><br />
<b>Test sample:</b><br />
<textarea
id="input"
style="max-width: 100%; width: 100%; height: 300px;"
></textarea>
<button onclick="run();">Run benchmark</button>
</div>
</div>
<div class="col-md-9">
<table style="width: 100%;">
<tr>
<td style="max-width: 150px; width: 150px;">
Anchorme
</td>
<td><div class="bench-bar" id="anchorme"></div></td>
</tr>
<tr>
<td style="max-width: 150px; width: 150px;">
Linkify
</td>
<td><div class="bench-bar" id="linkify"></div></td>
</tr>
<tr>
<td style="max-width: 150px; width: 150px;">
Autolinker
</td>
<td>
<div class="bench-bar" id="autolinker"></div>
</td>
</tr>
</table>
<p style="text-align: right;">
<i>Number of operations per 500ms, higher is better</i>
</p>
</div>
</div>
</div>
<footer class="bs-docs-footer" role="contentinfo">
<div class="container">
<p>
Licensed under
<a href="http://opensource.org/licenses/MIT" target="_blank"
>MIT License</a
>
</p>
<p>
Documentation template by
<a href="http://getbootstrap.com">Bootstrap team</a>
</p>
<ul class="bs-docs-footer-links muted">
<li>·</li>
<li>
<a href="https://github.com/alexcorvi/anchorme.js"
>GitHub</a
>
</li>
<li>·</li>
<li>
<a
href="https://github.com/alexcorvi/anchorme.js/issues?state=open"
>Issues</a
>
</li>
</ul>
</div>
</footer>
<script
src="./dist/browser/anchorme.js"
type="text/javascript"
></script>
<script src="https://cdn.jsdelivr.net/npm/linkifyjs@4.1.1/dist/linkify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/linkify-string@4.1.1/dist/linkify-string.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/autolinker@4.0.0/dist/autolinker.min.js"></script>
<script type="text/javascript">
function test(toTest) {
let iterations = 0;
const stopAt = new Date().getTime() + 500;
do {
toTest();
iterations++;
} while (new Date().getTime() < stopAt);
return iterations;
}
function placeLongText() {
let longText = `Library works with (http://www.google.com) or without (www.google.com) protocols in link. It works well on paths [www.github.io/something/something] and queries <wordpress.com/post.php?p=112> and even when query starts immediately after the TLDS "wordpress.com?p=112". This library does validation against a full IANA list, so for example this link will be detected: 'alex.photography', yet this one will not 'alex.photograph'. Some links might also have ports in them like this one (https://a.co:8999/ab.php?p=12). Some are actually an IP (127.0.0.1/should_(be)_detected, invalid:127.0.0.300/should/not(be)_detected). Local machine names URLs are detected only when preceded by a protocol (https://localhost/abc, ftps://hostname, http://local:123?abc=xyz.) Links with non-english alphabets are considered as non-valid, yet they are commonly used in chat application and so, so we supported them (to some degree). (examples: ka.wikipedia.org/wiki/მთავარი_გვერდი, ka.wikipedia.org/wiki/ბაქო, ka.wikipedia.org/wiki/2_აპრილი, ka.wikipedia.org/wiki/მერი_(სპილო)). Encoded links works too (example:ka.wikipedia.org/wiki/%E1%83%91, mailto:mail@xn--ngbrx4e.com). Emails are detected too: (valid: email@ex.com e.mail@ex.com e-mail@ex.com e+mail@ex.com e_mail@example.com 123@ex.com 123.123@ex.com email@sub.domain.com email@ex.co.jp email@123.123.123.123) (invalid email.@example.web email@example email@example.abcd email@111.222.333.444). Files (when starting with file:/// protocol) are detected too. (file:///c:/somefile.zip). Tokenization is as accurate as it can get, you can see from the above text that we've tried almost all common punctuation marks and the library detected links from between them.`;
for (let index = 0; index < 4; index++) {
longText = longText + longText;
}
document.getElementById("input").value = longText;
run();
}
function placeShortText() {
document.getElementById("input").value =
"here's a link: (www.github.com)";
run();
}
function placeMediumText() {
document.getElementById(
"input"
).value = `Library works with (http://www.google.com) or without (www.google.com) protocols in link. It works well on paths [www.github.io/something/something] and queries <wordpress.com/post.php?p=112> and even when query starts immediately after the TLDS "wordpress.com?p=112". This library does validation against a full IANA list, so for example this link will be detected: 'alex.photography', yet this one will not 'alex.photograph'. Some links might also have ports in them like this one (https://a.co:8999/ab.php?p=12). Some are actually an IP (127.0.0.1/should_(be)_detected, invalid:127.0.0.300/should/not(be)_detected). Local machine names URLs are detected only when preceded by a protocol (https://localhost/abc, ftps://hostname, http://local:123?abc=xyz.) Links with non-english alphabets are considered as non-valid, yet they are commonly used in chat application and so, so we supported them (to some degree). (examples: ka.wikipedia.org/wiki/მთავარი_გვერდი, ka.wikipedia.org/wiki/ბაქო, ka.wikipedia.org/wiki/2_აპრილი, ka.wikipedia.org/wiki/მერი_(სპილო)). Encoded links works too (example:ka.wikipedia.org/wiki/%E1%83%91, mailto:mail@xn--ngbrx4e.com). Emails are detected too: (valid: email@ex.com e.mail@ex.com e-mail@ex.com e+mail@ex.com e_mail@example.com 123@ex.com 123.123@ex.com email@sub.domain.com email@ex.co.jp email@123.123.123.123) (invalid email.@example.web email@example email@example.abcd email@111.222.333.444). Files (when starting with file:/// protocol) are detected too. (file:///c:/somefile.zip). Tokenization is as accurate as it can get, you can see from the above text that we've tried almost all common punctuation marks and the library detected links from between them. Library doesn't break your HTML, so an HTML attribute that has a link in it will not be broken <img src='http://dummyimage.com/30'> or a link that is already inside an attribute, will not be broken (e.g. <a href="https://github.io">https://github.io</a>).`;
run();
}
async function run() {
setTimeout(() => {
if (document.getElementById("input").value === "") {
placeShortText();
}
const str = document.getElementById("input").value;
const Ai = test(() => {
anchorme({
input: str,
options: {
skipHTML: false
}
});
});
const Bi = test(() => {
linkifyStr(str);
});
const Ci = test(() => {
Autolinker.link(str);
});
const max = Math.max(Ai, Bi, Ci);
const AP = Math.round((Ai / max) * 100);
const BP = Math.round((Bi / max) * 100);
const CP = Math.round((Ci / max) * 100);
document.getElementById("anchorme").innerHTML = `${Ai} ${
100 - AP ? `- ${AP}%` : "Fastest"
}`;
document.getElementById("linkify").innerHTML = `${Bi} ${
100 - BP ? `- ${BP}%` : "Fastest"
}`;
document.getElementById("autolinker").innerHTML = `${Ci} ${
100 - CP ? `- ${CP}%` : "Fastest"
}`;
document.getElementById("anchorme").style.width = `${AP}%`;
document.getElementById("linkify").style.width = `${BP}%`;
document.getElementById(
"autolinker"
).style.width = `${CP}%`;
});
}
placeMediumText();
run();
</script>
</body>
</html>