in reply to Re: (Efficiently) comparing arrays
in thread comparing arrays

Heh, wow. I guess simplicity is bliss sometimes. I took the liberty of using your benchmarking program, and added my function to compare to faq. The function i had come up with and was using was
sub maptest { my ($low, $high) = @_; my $i=0; return 0 if @$low != @$high; map{return 0 if $_ ne $low->[$i++]}@$high; return 1; } __END__ with my @first = ((1..200), qw(a b c d e f)) ; my @second= ((1..200), qw(b a c d e f)) ; Benchmark: timing 20000 iterations of faq, map... faq: 8 wallclock secs ( 8.44 usr + 0.00 sys = 8.44 CPU) map: 10 wallclock secs ( 9.64 usr + 0.00 sys = 9.64 CPU)
Needless to say they were nearly identical for a difference at the start of the array.
Thanks for all the help!

Replies are listed 'Best First'.
(MeowChow) Re3: (Efficiently) comparing arrays
by MeowChow (Vicar) on Apr 04, 2002 at 10:19 UTC
    The only reason that this is slower than the faq answer, or the solution i just posted, is that you are using map in void context. This is an efficiency no-no.

    update: demerphq is also correct, removing the lexical context indeed contributes some of the performance increase. Since this is a one-time performance penalty, its effect will be greater relative to smaller arrays.

       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      And also because the map he used has a lexically scoped block but the for loop that you used does not. Handling the scope has an overhead associated with it im pretty sure.

      just my $0.02

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.