Benchmarking Local Hostname Lookup Methods

Benchmarking Local Hostname Lookups


The Sys::Hostname module (shipped with perl!) provides a hostname() function. How much better is it then `hostname`?
  • use Sys::Hostname;                   |
    my $host = hostname();               |           my $host = `hostname`;
    
  • As you can see, the hostname system call is simplier, and we don't have to load a module
    I quickly made this program lets see the results!
  • perl benchmark_hostname_techniques.pl 
    module method:  91 wallclock secs (31.64 usr           +               0.18 sys =  31.82 CPU) @ 690179.82/s (n=21961522)
    system method: 218 wallclock secs ( 7.33 usr 22.78 sys + 36.22 cusr 103.38 csys = 169.71 CPU) @   4896.51/s (n=147434)
    
  • The Module method WINS it was able to run 140 more times then the system call, and in less then half the time using 5x less CPU!

    System specs: Perl 5.8.8 Single proc, fedora 8