pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/WebReflection/hyperHTML/commit/26296a0654ebfdf792a6422aed5b69c98dd50b0c

"anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-9c8f61f9f58ad7b2.css" /> added fuzzysort bench · WebReflection/hyperHTML@26296a0 · GitHub
Skip to content

Commit 26296a0

Browse files
author
Andrea Giammarchi
committed
added fuzzysort bench
1 parent 46c3550 commit 26296a0

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

test/fuzzysort.html

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<script defer src="https://unpkg.com/hyperhtml@latest/min.js"></script>
8+
<script>
9+
this.onnload = () => {
10+
const numberOfElements = 10000;
11+
const items = Array.apply(null, Array(numberOfElements)).map((el, i) => ({text: i})).sort(() => .5 < Math.random())
12+
const sortMethods = [
13+
() => 0,
14+
(a, b) => a.text - b.text,
15+
(a, b) => b.text - a.text
16+
];
17+
18+
function hyperHtmlTest() {
19+
20+
const $node = document.createElement('div');
21+
const $div = document.createElement('div');
22+
const $button = document.createElement('button');
23+
24+
const bound = hyperHTML.bind($div);
25+
const wire = hyperHTML.wire;
26+
27+
let sortMethodIndex = 0;
28+
29+
function render () {
30+
31+
const sortMethod = sortMethods[sortMethodIndex++ % sortMethods.length];
32+
bound`${items.concat().sort(sortMethod).map(
33+
item => wire(item)`<p>${item.text}</p>`
34+
)}`;
35+
}
36+
37+
$node.appendChild($button);
38+
$node.appendChild($div);
39+
40+
$button.textContent = 'HyperHTml Sort';
41+
$button.onclick = render;
42+
43+
return $node;
44+
45+
}
46+
47+
function normalHtmlTest() {
48+
49+
const $node = document.createElement('div')
50+
const $div = document.createElement('div')
51+
const $button = document.createElement('button')
52+
53+
let sortMethodIndex = 0
54+
55+
function render () {
56+
57+
const sortMethod = sortMethods[sortMethodIndex++ % sortMethods.length];
58+
59+
while($div.childNodes.length)
60+
$div.removeChild($div.childNodes[0]);
61+
62+
const frag = document.createDocumentFragment();
63+
64+
items.concat().sort(sortMethod).forEach(item => {
65+
66+
const p = document.createElement('p');
67+
68+
p.textContent = item.text;
69+
70+
frag.appendChild(p);
71+
72+
})
73+
74+
$div.appendChild(frag);
75+
76+
}
77+
78+
$node.appendChild($button);
79+
$node.appendChild($div);
80+
81+
$button.textContent = 'NormalHtml Sort';
82+
$button.onclick = render;
83+
84+
return $node;
85+
86+
}
87+
88+
document.body.appendChild(normalHtmlTest());
89+
document.body.appendChild(hyperHtmlTest());
90+
91+
};
92+
</script>
93+
</head>
94+
<body>
95+
96+
</body>
97+
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy