-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (128 loc) · 4.49 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Native JS: createdCallback</title>
<script src="lib/webcomponents.js"></script>
<script src="build/js-web-components.js"></script>
<script src="node_modules/basic-list-box/dist/basic-list-box.js"></script>
<link rel="import" href="polymer-packages/poly-component-1/src/poly-component-1.html">
<script>
var COMPONENT_TYPE_JAVASCRIPT = 'JavaScript';
var COMPONENT_TYPE_POLYMER = 'Polymer';
var TEST_TYPE_CREATEDCALLBACK = 'CreatedCallback';
var TEST_TYPE_DEEPMIXIN = 'Deep Mixin';
var numTests = 1;
var componentElement = null;
var componentType;
var testType;
var containerElement;
var resultsElement;
function onTestButtonClick() {
var inputElem = document.getElementById('loopTries');
numTests = inputElem.value;
var componentTypeElem = document.getElementById('componentType');
componentType = componentTypeElem.selectedItem.textContent;
var testTypeElem = document.getElementById('testList');
testType = testTypeElem.selectedItem.textContent;
containerElement = document.getElementById('componentContainer');
resultsElement = document.getElementById('resultsContainer');
switch (testType) {
case TEST_TYPE_CREATEDCALLBACK:
default:
createCallbackTest();
break;
case TEST_TYPE_DEEPMIXIN:
deepMixinTest();
break;
}
}
function deepMixinTest() {
var totalTime = 0;
for (var i = 0; i < numTests; i++) {
removeComponentFromPage();
var tag = getComponentTag();
componentElement = document.createElement(tag);
containerElement.appendChild(componentElement);
var timeStart, timeStop;
switch (componentType) {
case COMPONENT_TYPE_POLYMER:
default:
timeStart = performance.now();
componentElement.Behavior1_Method_1(1, 2);
timeStop = performance.now();
break;
case COMPONENT_TYPE_JAVASCRIPT:
timeStart = performance.now();
componentElement.Mixin1_Method_1(1, 2);
timeStop = performance.now();
break;
}
totalTime += timeStop - timeStart;
}
displayResults(totalTime);
}
function createCallbackTest() {
var timeStart = performance.now();
for (var i = 0; i < numTests; i++) {
runCreateCallbackTestInstance();
}
var timeStop = performance.now();
displayResults(timeStop - timeStart);
}
function runCreateCallbackTestInstance() {
removeComponentFromPage();
var tag = getComponentTag();
componentElement = document.createElement(tag);
containerElement.appendChild(componentElement);
}
function removeComponentFromPage() {
if (componentElement) {
componentElement.parentNode.removeChild(componentElement);
componentElement = null;
}
}
function displayResults(totalTime) {
var reportString = numTests + ' runs completed against ' + componentType +
'. ' + totalTime.toFixed(4) + ' milliseconds';
var reportElem = document.createElement('div');
reportElem.innerHTML = reportString;
resultsElement.appendChild(reportElem);
}
function getComponentTag() {
var tag;
switch (componentType) {
case 'Polymer':
default:
tag = 'poly-component-1';
break;
case 'JavaScript':
tag = 'js-component-1';
break;
}
return tag;
}
</script>
</head>
<body>
<h3>Timing tests for native JavaScript versus Polymer 1.0 components</h3>
<h3>Tests:</h3>
<basic-list-box id="testList" selection-required="true" aria-label="Tests" style="height: 50px; max-width: 250px;">
<div>CreatedCallback</div>
<div>Deep Mixin</div>
</basic-list-box>
<h3>Component type:</h3>
<basic-list-box id="componentType" selection-required="true" aria-label="Component type" style="height: 50px; max-width: 250px; margin-top: 20px">
<div>Polymer</div>
<div>JavaScript</div>
</basic-list-box>
<div style="margin-top: 40px;">
<span>Test runs:</span>
<input type="number" id="loopTries" value="1">
<input type="button" value="Test" onclick="onTestButtonClick()">
</div>
<div id="resultsContainer" style="margin-top: 20px"></div>
<div id="componentContainer"></div>
</body>
</html>