Don't know why everyone is so biased aganst posters that ask for a speed tip -- not everyone sits here and trys to pre-optimize every line of code -- as for the posters post how do you know that he does not have a finnished app in which he seems the tight inner loop running too slow for his needs?
Anyways, if the unix host has a shadowed passeord file most of the time normal users are allowed to read the /etc/passwd file as it has no password entries in it. you can slurp that file before you tight loop and make a hash of usernames then just check if they are defined. This will save you (on most systems getpwnam is not cached ...) the load /etc/passwd, search /etc/passwd steps per user lookup. I had this same problem at a site that had a very large password file where getpwnam was taking 10 seconds to run per call -- it speeded up my tight loop by 20 minutes.
-Waswas
Edited: one note with this method, there is a chance for a race condition if the password file is not sorda static -- if a user is added after you make the hash and before your tight loop is done the check with give you a false negitive match or if the user is deleted before the tight loop finishes a false positive.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.