A regex solution is significantly faster than a ST one.

Some benchmarks:

use warnings; use strict; use Benchmark qw(cmpthese); my $multiplier = 10_000; my $s__ = "abcdefghij" x $multiplier; # base string my $s10 = "Abcdefghij" x $multiplier; # 10% differ my $s50 = "ABCDEfghij" x $multiplier; # 50% differ my $s90 = "ABCDEFGHIj" x $multiplier; # 90% differ sub differ_at_st { my $i = 0; return [ map $_->[1], grep $_->[0] ne qq{\x00}, map [ $_, $i++ ], split '', $_[0] ^ $_[1] ]; } sub differ_at_rx { my $diff = $_[0] ^ $_[1]; my @diffs; push @diffs, $-[1] while $diff =~ m{ ([^\000]) }xmsg; return \@diffs; } print "multiplier == $multiplier \n"; cmpthese(-10, { st_10 => sub { differ_at_st($s__, $s10) }, st_50 => sub { differ_at_st($s__, $s50) }, st_90 => sub { differ_at_st($s__, $s90) }, rx_10 => sub { differ_at_rx($s__, $s10) }, rx_50 => sub { differ_at_rx($s__, $s50) }, rx_90 => sub { differ_at_rx($s__, $s90) }, });
Output:
C:\@Work\Perl\monks\745091>perl 745091_1.pl multiplier == 1000 Rate st_90 st_50 st_10 rx_90 rx_50 rx_10 st_90 10.7/s -- -0% -12% -49% -73% -94% st_50 10.7/s 0% -- -11% -49% -73% -94% st_10 12.1/s 13% 13% -- -42% -70% -93% rx_90 20.9/s 95% 95% 73% -- -48% -88% rx_50 40.0/s 274% 273% 230% 91% -- -77% rx_10 177/s 1562% 1555% 1367% 750% 344% -- C:\@Work\Perl\monks\745091>perl 745091_1.pl multiplier == 10000 Rate st_90 st_50 st_10 rx_90 rx_50 rx_10 st_90 1.03/s -- -2% -11% -50% -73% -94% st_50 1.05/s 2% -- -9% -49% -72% -94% st_10 1.15/s 13% 10% -- -44% -69% -93% rx_90 2.05/s 100% 96% 78% -- -45% -88% rx_50 3.76/s 267% 260% 226% 83% -- -77% rx_10 16.6/s 1513% 1483% 1334% 707% 340% --

In reply to Re^2: How do i do a direct comparison of an array of strings? by AnomalousMonk
in thread How do i do a direct comparison of an array of strings? by Anonymous Monk

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.