Well, let's benchmark and see. I created a /etc/passwd file with over 6000 users each named x and some number. Here I search for the user x1, x50, x1000, x3000, and x6000. I test with getpwnam and a regex. Each test is tried 1000 times and the output follows(All tests run on a PII-450 with 384MB RAM running Redhat 9):

#!/usr/bin/perl -w use Benchmark; for $x (1, 50, 1000, 3000, 6000){ timethese (1000,{ "getpwnam${x}" => q { $there=getpwnam("x${x}") }, "regex${x}" => q {open(PASSWD,"/etc/passwd"); while(<PASSWD>) { if (/^x${x}:/){$alsothere=1}; last if $alsothere == 1; } close PASSWD;}, }); } Benchmark: timing 1000 iterations of getpwnam1, regex1... getpwnam1: 0 wallclock secs ( 0.13 usr + 0.05 sys = 0.18 CPU) @ 55 +55.56/s (n=1000) (warning: too few iterations for a reliable count) regex1: 0 wallclock secs ( 0.10 usr + 0.03 sys = 0.13 CPU) @ 76 +92.31/s (n=1000) (warning: too few iterations for a reliable count) Benchmark: timing 1000 iterations of getpwnam50, regex50... getpwnam50: 1 wallclock secs ( 0.29 usr + 0.02 sys = 0.31 CPU) @ 32 +25.81/s (n=1000) (warning: too few iterations for a reliable count) regex50: 0 wallclock secs ( 0.08 usr + 0.05 sys = 0.13 CPU) @ 76 +92.31/s (n=1000) (warning: too few iterations for a reliable count) Benchmark: timing 1000 iterations of getpwnam1000, regex1000... getpwnam1000: 2 wallclock secs ( 2.36 usr + 0.24 sys = 2.60 CPU) @ +384.62/s (n=1000) regex1000: 0 wallclock secs ( 0.10 usr + 0.04 sys = 0.14 CPU) @ 71 +42.86/s (n=1000) (warning: too few iterations for a reliable count) Benchmark: timing 1000 iterations of getpwnam3000, regex3000... getpwnam3000: 8 wallclock secs ( 7.26 usr + 0.43 sys = 7.69 CPU) @ +130.04/s (n=1000) regex3000: 1 wallclock secs ( 0.12 usr + 0.05 sys = 0.17 CPU) @ 58 +82.35/s (n=1000) (warning: too few iterations for a reliable count) Benchmark: timing 1000 iterations of getpwnam6000, regex6000... getpwnam6000: 16 wallclock secs (14.73 usr + 0.67 sys = 15.40 CPU) @ +64.94/s (n=1000) regex6000: 0 wallclock secs ( 0.13 usr + 0.06 sys = 0.19 CPU) @ 52 +63.16/s (n=1000) (warning: too few iterations for a reliable count)

Suprisingly the regex wins hands down. Not too shabby. I don't think you need to worry about your script being slow at all.

HTH


In reply to Re: User Existance? by pzbagel
in thread User Existance? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.