in reply to Re^3: opening a file in a subroutine
in thread opening a file in a subroutine
Please go back and actually read the benchmark code in the little readmore tag there.
1. Your code, not exact, modified for clear comparison:
This is a moderately less efficient version of the code in $subs{while_io} . The code in particular is
2. My code,push @_,$_ while <$fh>;
This is the code in $subs{list_io}. The code in particular is@lines = <FILE>;
They are two different animals, my version slurps the file, when your version does not. There is the performance difference.@line= <$fh>;
Yes correct. The code in $subs{split_slurp} is measurably faster than either of the above solutions (for files that fit in memory and on my machine here). In addition both methods you mention are benchmarked. The second on small files moderately out performs the first. And split_slurp outperforms them both in similar conditions. Only while_io is suitable for really large files. And as the other posts mention, at least on Win32 Perl 5.6 list_io hangs on large files.
Your benchmark data is not relevant to my solution at all.
Your solution (insofar as <> in list context can be called your solution) is benchmarked along side two others. It is slower than one of the others according to the benchmark. What more is there to be said?
UpdateBenchmark: running list_io, split_slurp, while_io, each for at least 5 + CPU seconds... Rate while_io list_io split_slurp while_io 1629/s -- -5% -40% list_io 1722/s 6% -- -37% split_slurp 2725/s 67% 58% --
Please don't add stuff to nodes and not put an update note on.
As for the size/slurp, my slurp is localized. It wont infect the rest of a script, furthermore the entire way through this discussion we have been discussing files that can be processed in memory Ie the 8.5MB word file, or $0 of the benchmark itself. The other use was a solution to do something in someones code where the effects of the localization, and reading in such a large file and then evaling it (!!?) practically required a notice that it was a bad solution. Here matters are much more constrained, and as such slurping isn't out of line. Consider the OP is using it happily right now (apparently).
Update 2
The original node there has been completely rewritten three times.
Thats way out of line dude. The community here is about sharing knowledge and having a good time. I posted a benchmark. You updated your node with a bunch of stuff that demonstratably not true in a least one instance. I called you on it. Fine. Somebody out there might learn something from this exchange. Get over it, and don't rewrite history because you made a mistake. If everyone did that the archives would be full of holes. Hell theres a few nodes I wish I didnt write. They are still here.
Anyway, since your rewriting history today this conversation is over.
--- demerphq
my friends call me, usually because I'm late....
|
|---|