|Don't ask to ask, just ask|
Re^5: use File::Slurp for (!"speed");by revdiablo (Prior)
|on Nov 09, 2004 at 22:07 UTC||Need Help??|
The original poster's argument is that their system slurps files that fall below the break-even point for File::Slurp. It's therefore more efficient (in runtime speed) to use inline idiomatic slurp.
Indeed, I acknowledged that when I said, "don't get me wrong. I'm not trying to disagree with your main point. In your particular case, switching to File::Slurp was probably not the right idea."
A fairer benchmark would compare the slurp methods as they'll be used. Since idiomatic slurp doesn't require a function call, it seems sensible not to add the extra overhead into the benchmark.
Perhaps the idiomatic slurp is almost always used inline, but that was not an assumption I was willing to make. I've used the idiomatic slurp wrapped in a subroutine before, and it's not inconceivable to me that others would do the same. I was trying to compare the speed of the two slurp methods, not the speed of their most common usage patterns.
I figured some folks would take issue with that, which is why I wrote the paragraph explaining my reasoning. Looking back, I probably should have just included the inline version in my benchmark in the first place, rather than trying to explain it away.
I'm sure there's a point where File::Slurp's efficiency overwhelms the function call penalty. It would be interesting to see where that point actually is, even though it probably varies from one system to another.
Then let's find out, shall we? Here's an updated version of the benchmark:
And here are the results I got:
The 50k test is rather strange. The IS in a sub is only 3% slower than it is inline, with FS 14% faster. But past that point, FS and the inline IS are essentially neck-in-neck. FS starts to pull away once we get into the 5m and 25m tests, but at this point, slurping seems a bit dubious. Like you said, this is probably all system-dependent, but interesting nonetheless.