in reply to Re: using hash uniqueness to find the odd man
in thread using hash uniqueness to find the odd man

oak. here's the code. (i changed to ++). the files handles are just where i am reading the DNs from.
while (<XCH0S>) { @array = split(",", $_); $array[2] =~ tr/A-Z/a-z/; chomp $array[2]; $xch0{$array[2]}++; } while (<XCH3S>) { @array2 = split(",", $_); $array2[2] =~ tr/A-Z/a-z/; chomp $array2[2]; if (!defined $xch0{$array2[2]}) { print "DN of extra record is: $array2[2]"; } else { next; } }

i tested this against your hash implementation and i got these benchies:
Benchmark: timing 10000 iterations of my code, their code... my code: 1 wallclock secs ( 0.92 usr + 0.06 sys = 0.98 CPU) @ 10 +193.68/s (n=10000) their code: 0 wallclock secs ( 0.13 usr + 0.05 sys = 0.18 CPU) @ 55 +555.56/s (n=10000) (warning: too few iterations for a reliable count) C:\network>cmp2.pl Benchmark: timing 110000 iterations of my code, their code... my code: 3 wallclock secs ( 1.97 usr + 0.51 sys = 2.48 CPU) @ 44 +301.25/s (n=110000) their code: 2 wallclock secs ( 1.63 usr + 0.37 sys = 2.00 CPU) @ 54 +917.62/s (n=110000) C:\network>cmp2.pl Benchmark: timing 1000000 iterations of my code, their code... my code: 16 wallclock secs (11.07 usr + 4.80 sys = 15.86 CPU) @ 63 +043.75/s (n=1000000) their code: 18 wallclock secs (13.78 usr + 4.59 sys = 18.37 CPU) @ 54 +445.47/s (n=1000000) C:\network>cmp2.pl Benchmark: timing 2000000 iterations of my code, their code... my code: 33 wallclock secs (21.50 usr + 9.36 sys = 30.86 CPU) @ 64 +800.41/s (n=2000000) their code: 40 wallclock secs (28.05 usr + 8.83 sys = 36.88 CPU) @ 54 +226.99/s (n=2000000)


UPDATE: thank you node=tachyon for pointing out those typos - working from two different versions - sorry for the confusion.


humbly,
novitiate

"...goodnight you princes of main(e)"  --The Cider House Rules

Replies are listed 'Best First'.
Re: Re: Re: using hash uniqueness to find the odd man
by tachyon (Chancellor) on Jul 11, 2001 at 16:43 UTC

    Looks about the same, as expected as the hash methodology is the same. However the code you have posted does not actually do much, I presume they are typos, but if you tested this code the results dont mean much I'm afraid. In the second while loop you set up @array2 but then refer to @array - which because you do not lexically scope it using 'my' will be set to the last value found in the first while loop. You also do not set $dn so this will always be null. You don't need the else next bit at the end BTW - you do not gain anything from this as you are already at the end of the loop block. I would be interested as to how this code goes if you have time to test it.

    while (<XCH0S>) { chomp; tr/A-Z/a-z/; $xch0{(split",")[2]}++; } while (<XCH3S>) { chomp; tr/A-Z/a-z/; my $dn = (split",")[2]; print "DN of extra record is: $dn\n" if !defined $xch0{$dn}; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print