What about something like:

#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); my $testdir = $ARGV[0]; my @filelist; # Code example taken from Time::HiRes documentation opendir(D, $testdir) or die $!; my $t0 = [gettimeofday]; @filelist = readdir(D) or die $!; my $t1 = [gettimeofday]; closedir D; my $t0_t1 = tv_interval $t0, $t1; print q{Scan time for directory }, $testdir, q{ : }, $t0_t1, qq{ seconds\n}; print q{Total entries in directory }, $testdir, q{ : }, scalar @filelist, qq{\n};

Example output:

$ perl readdir-test.pl . Scan time for directory . : 3.5e-05 seconds Total entries in directory . : 4 $ perl readdir-test.pl test/ Scan time for directory test/ : 0.113722 seconds Total entries in directory test/ : 68115 $ perl readdir-test.pl test2/ Scan time for directory test2/ : 1.475231 seconds Total entries in directory test2/ : 412483

HTH.

Updated: 14-Aug-2007
Added example for directory test/ containing 412483 entries.


In reply to Re: How to time a directory scan by atcroft
in thread How to time a directory scan by graff

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.