in reply to Re: Speed of opening and closing a file 1000s times
in thread Speed of opening and closing a file 1000s times
After a couple of runs, it seems that the following is about what you get with multiple open filehandles that you juggle:sub multiplex { my @my_array; foreach my $entry (@array) { open my $fh => ">", $entry->[0].".mu" or die "open: $!"; push @my_array, [$fh, $entry->[1]]; } open my $fh => $file or die "open: $!"; while (<$fh>) { foreach my $entry (@my_array) { print {$entry->[0]} $_ if /$entry->[1]/; } } foreach my $entry (@my_array) { close($entry->[0]) or die "close: $!"; } }
which shows that not opening/closing multiple filehandles is a win, but it is much slower than repeated passes, and I have to wonder why. (One thing that I am wondering is how much caching files at the OS level could make a difference.)s/iter multiplex one multiplex 1.65 -- -87% one 0.209 690% --
For the record, my trial was done on Debian with Perl 5.8.1.
|
|---|