I'd be interested in seeing your results. I did some some benchmarking too, and found that the regex is slower.

Here's the program (using my soon to be released 'Benchmark::Sized' module) and the results.

#!/usr/bin/perl use strict; use warnings qw 'all'; use Benchmark::Sized; use vars qw /@array/; my $stats = sized_timethese run_for => 2, steps => 8, start_size => 1, end_size => 1000, seed => sub { @main::array = map {join "" => map {chr rand 128} 1 .. $_ [0]} + 1 .. 20 }, code => { regex => 'my @foo = grep {! /^\.\.?\Z/} @main::array', ne => 'my @foo = grep {$_ ne "." and $_ ne ".."} @main::ar +ray', } ; print "Runs/second for regex vs ne:\n"; print_timed $stats, type => 'sized'; __END__ Runs/second for regex vs ne: Size ne regex 1: 20744.28 12809.79 3: 22549.51 13048.06 7: 23110.45 12337.91 19: 21600.00 12560.28 52: 21005.50 12276.56 139: 19269.95 11891.63 373: 18345.79 11220.29 1000: 14422.54 9634.74

Abigail


In reply to Re: Create a list of directories without . and .. by Abigail-II
in thread Create a list of directories without . and .. by BrowserUk

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.