Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit fe8632b

Browse files
committed
Add png-benchmark demo
1 parent 6488c53 commit fe8632b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

demo/png-benchmark.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const PDFDocument = require('../');
2+
const fs = require('fs');
3+
4+
const doc = new PDFDocument();
5+
6+
// files with alpha channel -> uses zlib.deflate
7+
const files = [
8+
'test.png',
9+
'test3.png'
10+
];
11+
12+
const filesData = files.map(fileName => {
13+
return fs.readFileSync(`images/${fileName}`);
14+
});
15+
16+
const iterationCount = 100;
17+
18+
console.time('png-bench')
19+
20+
for (let i = 0; i < iterationCount; i++) {
21+
filesData.forEach(data => {
22+
doc.image(data)
23+
doc.addPage()
24+
})
25+
}
26+
27+
doc.on('data', () => {})
28+
29+
doc.on('end', () => {
30+
console.timeEnd('png-bench');
31+
});
32+
33+
doc.end();

0 commit comments

Comments
 (0)