Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How smart is 'seek $fh, $pos, 0'?

by sundialsvc4 (Abbot)
on May 27, 2015 at 15:49 UTC ( #1128026=note: print w/replies, xml ) Need Help??


in reply to How smart is 'seek $fh, $pos, 0'?

Very interesting results, BrowserUK, and most certainly unexpected.   Every operating system, that I know of, provides an API-call that is equivalent to fseek().   I presume (but have not verified ...) that the perlguts simply uses that call.   I also have not verified that the underlying OS-implementation (in any particular OS ...) has any sort of dramatically-different execution time for any of the (usually, three) variations of that call.

Certainly, “seek from the end” would require a little bit of extra work, since one would need to be sure that the current size of the file was atomically and correctly known, even for a shared file.   But I would not expect the OS, nor Perl, to “cache the entire file” in order to determine that!

Anyhow ... “very interesting.”   I guess you learn something new every day.   Thanks for sharing.

Now, as for what the OP in this case should do, my instincts would tell me to tell him to “just be perfectly clear.”   To not be overly concerned about milliseconds unless those milliseconds actually matter.   (As I well know that, in your line of work, BrowserUK, they often do ... very much so.)   Use the system-call that most closely matches the way that you would describe your application’s intentions if you were describing it over the water-cooler, and to assume (hope?) that the call is “smart enough for peace work.”

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1128026]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2019-12-10 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?