5 ms·
Empirically, Perl's glob does not call the system glob. On my Linux system Perl (5.18.2) is slow but the system glob is fast. Create a file named /tmp/glob/$(pe
by rsc 9y ago
Empirically, Perl's glob does not call the system glob. On my Linux system Perl (5.18.2) is slow but the system glob is fast. Create a file named /tmp/glob/$(perl -e 'print "a"x100') in an otherwise empty /tmp/glob and then try:
$ cat tglob.pl
#!/usr/bin/perl
use Time::HiRes qw(clock_gettime);
$| = 1;
chdir "/tmp/glob" || die "$!";
for($i=0; $i<9; $i++) {
$pattern = ("a*"x$i) . "b";
$t = clock_gettime(CLOCK_REALTIME);
$mul = 10;
if($i >= 5){
$mul = 1;
}
for($j=0; $j<$mul; $j++) {
glob $pattern;
}
$t1 = clock_gettime(CLOCK_REALTIME);
printf("%d %.9f\n", $i, ($t1-$t)/$mul);
}
$ perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
...
$ perl tglob.pl
0 0.000004911
1 0.000016212
2 0.000088072
3 0.002416682
4 0.030226517
5 0.452545881
6 6.872966528
^C
You're the second person to claim that Perl calls the system glob though (someone in my blog comments did too). Maybe different versions of Perl do different things? This is Ubuntu 14.04 if that matters.
- demerphq 9y agoNo you are right. Modern perls use the BSD code in File::Glob.
- rsc 9y agoMore discussion at https://research.swtch.com/glob#comment-3272455315 https://research.swtch.com/glob#comment-3272455315
- rurban 9y agoIt uses the wrong system glob :) It either calls out on VMS or Windows to a perlglob executable, or uses BSD glob from a shared lib. So whenever perl makes a choice it makes the wrong one.