Simple text parsing in PHP7 is also faster than in Python, Ruby, Perl and NodeJS. I recently wrote some 1-liners to parse a 19Mb log file with a regex on my 2010 quad-core Mac. Python/Ruby: 2.2 secs. Perl: 1.4 secs. NodeJS: 0.9 secs. PHP7: 0.4 secs.
Ruby
IO.foreach('logs1.txt') {|x| puts x if /\b\w{15}\b/.match? x }
Python3
import re
with open('logs1.txt', 'rt') as fh:
for line in fh:
if re.search(r'\b\w{15}\b', line): print(line, end=' ')
Perl
open my $fh, '<', 'logs1.txt';
while (<$fh>) { chomp; say if $_ =~ /\b\w{15}\b/; }
close $fh;
NodeJS
var fs = require('fs'), byline = require('byline');
var stream = byline(fs.createReadStream('logs1.txt', {encoding: 'utf8'}));
stream.on('data', function(line) { if (line.match(/\b\w{15}\b/)) console.log(line); });
PHP
$fh = fopen('logs1.txt', 'r');
while (($line = fgets($fh)) !== false) {
if (preg_match('/\b\w{15}\b/', $line)) echo $line;
}
fclose($fh);