-
Notifications
You must be signed in to change notification settings - Fork 8
/
bench.cjs
43 lines (35 loc) · 1002 Bytes
/
bench.cjs
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
const { Document, serializeToWellFormedString } = require('.');
const TABLE_SIZE = 1000;
function createTable() {
const doc = new Document();
const table = doc.createElementNS("http://example.com", "table");
doc.appendChild(table);
for (let num = 1; num < TABLE_SIZE; ++num) {
const newRow = doc.createElementNS("http://example.com", "tr");
table.appendChild(newRow);
for (let i = 1; i < num; ++i) {
const newCell = doc.createElementNS("http://example.com", "td");
newRow.appendChild(newCell);
}
for (const row of table.childNodes) {
const newCell = doc.createElementNS("http://example.com", "td");
row.appendChild(newCell);
}
}
return doc;
}
console.group('createTable');
for (let i = 0; i < 20; ++i) {
console.time();
createTable();
console.timeEnd();
}
console.groupEnd();
console.group('serializeTable');
const doc = createTable();
for (let i = 0; i < 20; ++i) {
console.time();
serializeToWellFormedString(doc);
console.timeEnd();
}
console.groupEnd();