Figured I'd fix up the code and do more realistic benchmarks... code and results follow.
#!/usr/bin/perl -w use Benchmark; @a1 = qw(3 99 4 33 43 98 83 64 3 99 4 33 43 98 83 64 99 4 33 43 98 83 +64); @a2 = qw(3 99 4 33 43 98 83 64 3 99 4 11 43 98 83 64 99 4 33 43 98 83 +64); #middle different @a3 = qw(1 99 4 33 43 98 83 64 3 99 4 11 43 98 83 64 99 4 33 43 98 83 +64); #first different @a4 = qw(1); # different size sub join_eq { return join('',@{$_[0]}) eq join('', @{$_[1]} ); } sub quote_eq { return "@{$_[0]}" eq "@{$_[1]}"; } sub better_quote { if ("@{$_[0]}" eq "@{$_[1]}") { local $" = 'a'; return 1 if ("@{$_[0]}" eq "@{$_[1]}"); } return 0; } sub loop_eq { my ( $a1, $a2 ) = @_; return 0 if ($#$a1 != $#$a2); for ( 0 .. $#a1 ) { return 0 if ( $$a1[$_] ne $$a2[$_] ); } return 1; } print "\nEqual sized strings.\n"; timethese(-2, { join => q{ join_eq( \@a1, \@a1 ) }, quote => q{ quote_eq( \@a1, \@a1 ) }, bquoteSame => q{ better_quote( \@a1, \@a1 ) }, bquoteDiff => q{ better_quote( \@a1, \@a2 ) }, loopSame => q{ loop_eq( \@a1, \@a1 ) }, loopMid => q{ loop_eq( \@a1, \@a2 ) }, loopBeg => q{ loop_eq( \@a1, \@a3 ) } } ); print "\nDifferent sized.\n"; timethese(-2, { join => q{ join_eq( \@a1, \@a4 ) }, quote => q{ quote_eq( \@a1, \@a4 ) }, bquote => q{ quote_eq( \@a1, \@a4 ) }, loop => q{ loop_eq( \@a1, \@a4 ) } } );
Results...
Equal sized strings. Benchmark: running bquoteDiff, bquoteSame, join, loopBeg, loopMid, loo +pSame, quote, each for at least 2 CPU seconds... bquoteDiff: 2 wallclock secs ( 2.02 usr + 0.00 sys = 2.02 CPU) @ 21153.73/s (n=42794) bquoteSame: 2 wallclock secs ( 2.05 usr + 0.00 sys = 2.05 CPU) @ 10422.80/s (n=21398) join: 3 wallclock secs ( 2.10 usr + 0.00 sys = 2.10 CPU) @ 31310.51/s (n=65846) loopBeg: 2 wallclock secs ( 2.14 usr + 0.00 sys = 2.14 CPU) @ 30084.42/s (n=64501) loopMid: 2 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 13698.51/s (n=28534) loopSame: 2 wallclock secs ( 2.09 usr + 0.00 sys = 2.09 CPU) @ 8104.16/s (n=16962) quote: 3 wallclock secs ( 2.13 usr + 0.00 sys = 2.13 CPU) @ 20563.53/s (n=43862) Different sized. Benchmark: running bquote, join, loop, quote, each for at least 2 CPU +seconds... bquote: 2 wallclock secs ( 2.24 usr + 0.00 sys = 2.24 CPU) @ 31813.73/s (n=71390) join: 1 wallclock secs ( 2.13 usr + 0.00 sys = 2.13 CPU) @ 44310.68/s (n=94559) loop: 3 wallclock secs ( 2.00 usr + 0.00 sys = 2.00 CPU) @ 57423.08/s (n=114961) quote: 1 wallclock secs ( 2.11 usr + 0.00 sys = 2.11 CPU) @ 32110.27/s (n=67849)

In reply to RE: Comparing Arrays by Boogman
in thread Comparing Arrays by eak

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.