dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.91k stars 165 forks source link

Create some benchmarks #92

Open Redsandro opened 8 years ago

Redsandro commented 8 years ago

I don't know if I'm doing this right, but the jsonStream.stringifyObject() stream seems to take about 150% of the time of a normal JSON.stringify().

var obj = require('./test.json');
var now = require('performance-now');
var fs = require('fs');
var jsonStream = require('JSONStream');

var t, j;

t = now();
j = JSON.stringify(obj);
console.log(now() - t);

t = now();
j = jsonStream.stringifyObject();

for (key in obj)
    j.write([key, obj[key]]);                                                                                
j.end();

console.log(now() - t);

I was hoping to speed up the process of gzipping objects by stringifying them. But even if the stream means I can start gzipping before the stream is done, the overhead is significant.

I am guessing this might only be beneficial for memory preservation purposes?

It would be nice to see some benchmarks for proper scenarios.

Nepoxx commented 8 years ago

It's beneficial because it doesn't block, not because it's fast.