Here are two tests.

If both files (two 12000 lines of rand 10e6's) are presorted with unix sort (70ms each on a PIII 500MHz), you can narrow in with an approximation method (seek, read a character from each file, compare and cut the range in half again.. not a great algorithm maybe) to see where the byte streams diverge. My Perl program took 10ms to get there, and then I stopped working on it.. Diff is faster I think (under 1ms). Perl overhead for just making those calls, see below, is under 1ms, so two sorts and a diff are about 140ms. This resembles the hash time.

`sort oddbig > oddbigsort`; # these are all backticks `sort oddbig2 > oddbigsort2`; @ans = `diff oddbigsort oddbigsort2`; print "ANS: $ans[1]\n";

But those hash slices are positively gorgeous. They get my vote!

Incidentally japhy's code on the same system took 170 ms, see my implementation below. I wonder if the hash code involves something like a sort.

#!/usr/bin/perl -w use strict; use Benchmark; my $t = &Benchmark::timeit(1,' my %seen; my $f1="oddbigsort"; my $f2="oddbigsort2"; open (A,$f1); open (B,$f2); my @smaller_list = <A>; my @larger_list = <B>; if ($#larger_list < $#smaller_list) { @seen{@smaller_list} = (); delete @seen{@larger_list}; } else { @seen{@larger_list} = (); delete @seen{@smaller_list}; } my @culprits = keys %seen; foreach (@culprits) {print "$_\n";} close (A); close (B); '); print timestr($t),"\n";

In reply to Re: using hash uniqueness to find the odd man by mattr
in thread using hash uniqueness to find the odd man by novitiate

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.