Do you have two arrays, before and after sorting (yeah, I read that you don't want to compare the arrays...)? If yes, then for big arrays, you could write a simple test that compares n indices:
for my $r (@rand) { return 0 if $a[$r] ne $b[$r]; } return 1;
Not 100% safe of course, but if the input lines are not related, it should work. To be sure, you could apply a second test if the first test returned 1: Array::Compare uses join to compare two arrays. (This is probably fast enough even without the first test.)

If you don't have the two arrays, you won't get better than O(n) or you use a similar (unsafe) test like above - check if n blocks of size 2 are sorted.

UPDATE: md5 seems to be a little bit faster than join:

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all) ; use List::Util qw(shuffle); use Digest::MD5 qw(md5); open my $JOHN, '<', 'dictionary' or die $!; my @array = <$JOHN>; my @sorted = sort @array; $a = \@array; $b = \@sorted; timethese(5000, { 'join' => sub { return join('|',@$a) eq join('|', @$b); }, 'md5' => sub { return Digest::MD5::md5(@$a) eq Digest::MD5::md5(@$b) +; }, });
perl cmparray.pl Benchmark: timing 5000 iterations of join, md5... join: 29 wallclock secs (27.91 usr + 0.18 sys = 28.09 CPU) @ 17 +8.00/s (n=5000) md5: 27 wallclock secs (25.20 usr + 0.19 sys = 25.39 CPU) @ 19 +6.93/s (n=5000)

In reply to Re: Fast way to check if a sort was doen by lima1
in thread Fast way to check if a sort was doen by Outaspace

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.