Skip to content

Instantly share code, notes, and snippets.

@abhardwaj4
Created March 2, 2017 06:38
Show Gist options
  • Save abhardwaj4/f65779bccc77fcc1053c34e98eea0eba to your computer and use it in GitHub Desktop.
Save abhardwaj4/f65779bccc77fcc1053c34e98eea0eba to your computer and use it in GitHub Desktop.
FileWriteRead
var start = new Date();
var fs = require('fs');
var arr = [];
// Large Loop
for (var i = 0; i < 10000000; ++i) {
arr.push({x : i});
}
fs.writeFile('largefile.txt', JSON.stringify(arr), function(err){
if (err) {
return console.log(err);
}
console.log('Write Time = ' + (new Date() - start) + 'ms');
var end = new Date();
fs.readFile('largefile.txt', function(error, data){
if (error) {
return console.log(err);
}
var res = JSON.parse(data);
var readTime = new Date() - end;
console.log('Read and parse time = ' + readTime + 'ms');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment