-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf-test.html
More file actions
72 lines (66 loc) · 1.76 KB
/
Copy pathperf-test.html
File metadata and controls
72 lines (66 loc) · 1.76 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Performance test</title>
</head>
<body>
<p><a id="test1" href="#">Run Test 1</a></p>
<p><a id="testConsoleTimeStamp" href="#">Run console timeStamp</a></p>
<script>
function test1(e) {
console.time('test1');
var foo = [];
for (var i = 1; i <= 1000; i++) {
test2(foo, i);
}
console.timeEnd('test1');
}
function test2(foo, i) {
for (var j = 1; j <= 100000; j++) {
if (i * j % 211 === 0) {
test3(foo);
}
else {
foo.push(i * i - i);
}
}
}
var k = 0;
function test3(foo) {
if (k++ % 1733 === 0) {
console.count('test3');
test4();
}
foo = [];
}
function test4() {
var chars = document.documentElement.innerHTML.split('');
var word = [];
var text = [];
for (var c of chars) {
var current = charCode(c);
if ((current >= charCode('a') && current <= charCode('z')) || (current >= charCode('A') && current <= charCode('Z')) || (current >= charCode('0') && current <= charCode('9')) || current === charCode('-')) {
word.push(c);
}
else if (word.length > 0) {
text.push(word.join(''));
word.length = 0;
}
}
if (word.length > 0) {
text.push(word.join(''));
}
console.log(text.join(' ').length);
}
function charCode(a) {
return a.charCodeAt(0);
}
function testTimeStamp(foo) {
console.timeStamp('Hello world!');
}
document.getElementById('test1').addEventListener('click', test1);
document.getElementById('testConsoleTimeStamp').addEventListener('click', testTimeStamp);
</script>
</body>
</html>