This repository was archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 164
This repository was archived by the owner on Dec 4, 2018. It is now read-only.
Bad performance on JSONStream.stringify #131
Copy link
Copy link
Closed
Description
I have tried using JSONStream.stringify() and noticed the performance actually bad.
It takes 100x time to do the same thing I would do without streaming.
Please see the attached code below using JSONStream.
const fileSystem = require( "fs" );
const JSONStream = require( "JSONStream" );
const zlib = require('zlib');
const gzip = zlib.createGzip();
// Set timer
console.time("Timer");
var transformStream = JSONStream.stringify('[\n', ',\n', '\n]\n');
var outputStream = fileSystem.createWriteStream( __dirname + "/JSONStream.json" );
transformStream.pipe( outputStream );
for(var i=0; i<(250 * 18); i++){
transformStream.write({
child: Math.random().toString(36).substring(7),
parent: Math.random().toString(36).substring(7),
propertyName: Math.random().toString(36).substring(7),
provertyValue: Math.random().toString(36).substring(7)
});
}
transformStream.end();
outputStream.on(
"finish",
function handleFinish() {
console.timeEnd("Timer");
// Timer: 115267.364ms
}
);Using memory
const fs = require( "fs" );
// Set timer
console.time("Timer");
var outputStream = fs.createWriteStream( __dirname + "/nostream.json" );
var members = [];
for(var i=0; i<(25000 * 18); i++){
members.push({
child: Math.random().toString(36).substring(7),
parent: Math.random().toString(36).substring(7),
propertyName: Math.random().toString(36).substring(7),
provertyValue: Math.random().toString(36).substring(7)
});
}
outputStream.write(JSON.stringify(members));
outputStream.end();
outputStream.on(
"finish",
function handleFinish() {
console.timeEnd("Timer");
// Timer: 1267.696ms
}
);Is this expected performance?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels