Last active
April 1, 2016 13:08
-
-
Save yoava/fd291e13ef703a4ea68a33c463dc376a to your computer and use it in GitHub Desktop.
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
// sort1 uses a straightforward approach, sorting the records in a in-memory array | |
////////////////////////////////////////////////////////////////////////////////////// | |
var fs = require('fs'), | |
readline = require('readline'), | |
stream = require('stream'); | |
var start = Date.now(); | |
var data = []; | |
var rl = readline.createInterface({ | |
input: fs.createReadStream('./input.txt'), | |
terminal: false | |
}); | |
rl.on('line', function (line) { | |
data.push(line.split('\t')); | |
}); | |
rl.on('close', function () { | |
data.sort(function (a, b) { | |
return a[2].localeCompare(b[2]); | |
}); | |
var writer = fs.createWriteStream('out1.txt'); | |
data.forEach(line => writer.write(line.join('\t') + '\n')); | |
writer.end(); | |
var closetime = Date.now(); | |
console.log('Time. ', (closetime - start) / 1000, ' secs'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment