#!/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() { 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) @ 5555.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) @ 7692.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) @ 3225.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) @ 7692.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) @ 7142.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) @ 5882.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) @ 5263.16/s (n=1000) (warning: too few iterations for a reliable count)