Created
May 21, 2015 14:27
-
-
Save clarkgrubb/fde6190248c3d668ce33 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
$cat parse-json.js | |
#!/usr/bin/env node | |
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
rl.on('line', function(line) { | |
var data = JSON.parse(line); | |
data.new_field = 3; | |
console.log(JSON.stringify(data)); | |
}); | |
$ cat parse-json.py | |
#!/usr/bin/env python | |
import json | |
import sys | |
for line in sys.stdin: | |
data = json.loads(line) | |
data['new_field'] = 3 | |
print(json.dumps(data)) | |
$ wc enron-events-sentiment.json | |
518147 221392944 2091624861 enron-events-sentiment.json | |
$ time ./parse-json.js < enron-events-sentiment.json > tmp.json | |
real 0m40.884s | |
user 0m36.226s | |
sys 0m4.636s | |
$ time ./parse-json.py < enron-events-sentiment.json > tmp.json | |
real 0m52.010s | |
user 0m47.724s | |
sys 0m3.469s | |
$cat cat.js | |
#!/usr/bin/env node | |
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
rl.on('line', function(line) { | |
console.log(line); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment