Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
lc is much faster, it seems to me, though both are very fast (each of these tests below is for 1m comparisons, so regexp had 150K/s, and lc 1830K/s).
Benchmark: timing 10 iterations of RegExp, lc... RegExp: 66 wallclock secs (66.20 CPU) @ 0.15/s (n=10) lc: 6 wallclock secs ( 5.47 CPU) @ 1.83/s (n=10)
#!/usr/bin/perl use warnings; use strict; use Benchmark; use constant SIZE => 1000; our @a1 = map { "a".$_ } (1..SIZE); our @a2 = map { "A".$_ } (1..SIZE); sub use_re { my $count = 0; foreach my $i (@a1) { foreach my $j (@a2) { if ($i =~ /^\Q$j\E$/i) { $count++; } } } die unless $count == SIZE; } sub use_lc { my $count = 0; foreach my $i (@a1) { foreach my $j (@a2) { if (lc $i eq lc $j) { $count++; } } } die unless $count == SIZE; } timethese(10, { RegExp => \&use_re, lc => \&use_lc, });

In reply to Re: Comparing strings case insensitive by sgifford
in thread Comparing strings case insensitive by zemane

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found