forked from exceljs/exceljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
64 lines (56 loc) · 2.46 KB
/
benchmark.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
const fs = require('fs');
const path = require('path');
const ExcelJS = require('./lib/exceljs.nodejs.js');
const runs = 3;
runProfiling('huge xlsx file', () => {
return new Promise((resolve, reject) => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const stream = fs.createReadStream(path.join(__dirname, 'spec/integration/data/huge.xlsx'));
const wb = new ExcelJS.stream.xlsx.WorkbookReader();
wb.read(stream, {
entries: 'emit',
sharedStrings: 'cache',
worksheets: 'emit',
});
let worksheetCount = 0;
let rowCount = 0;
wb.on('worksheet', worksheet => {
worksheetCount += 1;
console.log(`Reading worksheet ${worksheetCount}`);
worksheet.on('row', () => {
rowCount += 1;
if (rowCount % 50000 === 0) console.log(`Reading row ${rowCount}`);
});
});
wb.on('end', () => {
console.log(`Processed ${worksheetCount} worksheets and ${rowCount} rows`);
resolve();
});
wb.on('error', reject);
});
});
async function runProfiling(name, run) {
console.log('');
console.log('####################################################');
console.log(`WARMUP: Current memory usage: ${currentMemoryUsage({runGarbageCollector: true})} MB`);
console.log(`WARMUP: ${name} profiling started`);
const warmupStartTime = Date.now();
await run();
console.log(`WARMUP: ${name} profiling finished in ${Date.now() - warmupStartTime}ms`);
console.log(`WARMUP: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`WARMUP: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
for (let i = 1; i <= runs; i += 1) {
console.log('');
console.log('####################################################');
console.log(`RUN ${i}: ${name} profiling started`);
const startTime = Date.now();
await run(); // eslint-disable-line no-await-in-loop
console.log(`RUN ${i}: ${name} profiling finished in ${Date.now() - startTime}ms`);
console.log(`RUN ${i}: Current memory usage (before GC): ${currentMemoryUsage({runGarbageCollector: false})} MB`);
console.log(`RUN ${i}: Current memory usage (after GC): ${currentMemoryUsage({runGarbageCollector: true})} MB`);
}
}
function currentMemoryUsage({runGarbageCollector}) {
if (runGarbageCollector) global.gc();
return Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100;
}