4 ms·
That's a fair criticism. I know Perl can do pretty amazing things with text, but I've never bothered to learn it. EDIT: I decided to ask GPT-4 to translate the
by sgarland 3y ago
That's a fair criticism. I know Perl can do pretty amazing things with text, but I've never bothered to learn it.
EDIT: I decided to ask GPT-4 to translate the gawk script to Perl. I make zero claims that this is ideal (as stated, I don't know Perl at all), but it _does_ produce the same output, but slightly slower than the gawk script.
$ hyperfine "perl -lane '\$ips{\$F[0]}++; END {print \"\$ips{\$_} \$_\" for (sort {\$ips{\$b} <=> \$ips{\$a}} keys %ips)[0..9]}' fake_log.txt"
Benchmark 1: perl -lane '$ips{$F[0]}++; END {print "$ips{$_} $_" for (sort {$ips{$b} <=> $ips{$a}} keys %ips)[0..9]}' fake_log.txt
Time (mean ± σ): 1.499 s ± 0.006 s [User: 1.447 s, System: 0.050 s]
Range (min … max): 1.490 s … 1.507 s 10 runs
- ajross 3y agoI would have gone with an iteratively-built list, FWIW, and avoided the overhead in parsing fields the script won't use: perl -e 'for $i (<>) { $i =~ s/ .*//; push @list, $i; }; print(sort(@list));'