Created
March 2, 2017 06:38
-
-
Save abhardwaj4/f65779bccc77fcc1053c34e98eea0eba to your computer and use it in GitHub Desktop.
FileWriteRead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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