/
dom-bundle.js
183 lines (135 loc) · 5.55 KB
/
dom-bundle.js
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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var executionTimes = [],
startTime = null,
//Explicitly copying, as I'm skeptical, when the #'s never change
initMemory = {
jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
totalJSHeapSize: performance.memory.totalJSHeapSize,
usedJSHeapSize: performance.memory.usedJSHeapSize
};
//Read url params for: maxRows
var getMaxRows = function getMaxRows() {
var result = 500;
var loc = location.search.slice(1);
if (loc) {
var params = {};
var tokens = loc.split('&');
tokens.forEach(function (token) {
var bits = token.split('=');
params[bits[0].toLowerCase()] = bits[1];
});
if (params['maxRows'.toLowerCase()]) {
result = parseInt(params['maxRows'.toLowerCase()], 10);
}
}
console.log("getMaxRows(): ", result);
return result;
};
//////////////
module.exports = {
maxRows: getMaxRows(),
pageSize: 50,
updateEvery: 750,
rows: [],
runApp: function runApp(worker) {
if (!startTime) {
startTime = performance.now();
}
var _lib = this;
var updateInterval = setInterval(function () {
if (_lib.rows.length < _lib.maxRows) {
//Simulate that user 'scrolled' to bottom
// simulate updating model with server results, after a scroll
var pageSet = _lib.getNextPageSet();
_lib.rows = _lib.rows.concat(pageSet);
var t0 = performance.now();
worker(pageSet, _lib.rows);
var t1 = performance.now();
_lib.scrollToBottom();
_lib.addExecutionTime(t1 - t0);
} else {
clearInterval(updateInterval);
_lib.printSummary();
}
}, _lib.updateEvery);
},
addExecutionTime: function addExecutionTime(time) {
executionTimes.push(time);
},
getNextPageSet: function getNextPageSet() {
var pageSet = [];
var last = this.rows[this.rows.length - 1];
for (var i = 0; i < this.pageSize; i++) {
var id = (last ? last.id : 0) + 1;
var row = {
id: id,
rowNum: id,
artist: 'Artist ' + id,
album: 'Album ' + id
};
last = row;
pageSet.push(row);
}
return pageSet;
},
mean: function mean(sequence) {
var sum = 0;
sequence.forEach(function (val) {
sum += val;
});
return sum / sequence.length;
},
median: function median(sequence) {
//copy
sequence = sequence.slice();
// note that direction doesn't matter
sequence.sort(this.sortAscending);
if (sequence.length >= 3) {
return sequence[Math.ceil(sequence.length / 2)];
}
return sequence[0];
},
printSummary: function printSummary() {
executionTimes.sort(this.sortAscending);
var meanValue = this.mean(executionTimes).toFixed(4);
var medianValue = this.median(executionTimes).toFixed(4);
var finalTime = performance.now();
var totalTime = (finalTime - startTime).toFixed(4);
var printMemory = function printMemory(target) {
return 'jsHeapSizeLimit: ' + target.jsHeapSizeLimit + ', totalJSHeapSize: ' + target.totalJSHeapSize + ', usedJSHeapSize: ' + target.usedJSHeapSize;
};
var stats = ["------------------------------", "Execution completed with parameters: ", "maxRows: " + this.maxRows, "------------------------------", 'Execution times: ' + executionTimes, 'Avg. time: ' + meanValue + 'ms', 'Median time: ' + medianValue + 'ms', 'Total time: ' + totalTime + 'ms, ' + (totalTime / 1000).toFixed(2) + 's', "------------------------------", 'Initial memory: ' + printMemory(initMemory), 'Final memory: ' + printMemory(performance.memory)];
var div = document.createElement('div');
div.innerHTML = stats.join('<br/>');
document.body.appendChild(div);
this.scrollToBottom();
},
scrollToBottom: function scrollToBottom() {
var docHeight = document.body.offsetHeight;
docHeight = docHeight == undefined ? window.document.documentElement.scrollHeight : docHeight;
//console.log("scrollToBottom() - scroll to docHeight: ", docHeight);
window.scrollTo(0, docHeight);
},
sortAscending: function sortAscending(a, b) {
return a - b;
}
};
},{}],2:[function(require,module,exports){
'use strict';
var lib = require('./common.js');
//////
var table = document.getElementById('item_table_body');
var rows = [];
lib.runApp(function (pageSet, allRows) {
// simulate updating model with server results, after a scroll
pageSet.forEach(function (row) {
writeRow(row);
});
});
function writeRow(row) {
var tr = document.createElement('tr');
tr.innerHTML = "<td>" + row.rowNum + "</td>" + "<td> </td>" + "<td>" + row.artist + "</td>" + "<td>" + row.album + "</td>";
table.appendChild(tr);
}
},{"./common.js":1}]},{},[2]);