Why is this a reply to me?
I do not get your point...

...but I "can't hold my water" anyways:
If this is a reminder that I forgot in my (possibly silly ;-) benchmark a viable alternative, I assure you that a for-loop counting each characters occurences isn't a viable alternative if you're interested in /one/ character only, as is the OP. ¹

kind regards,
tomte


¹ silly me: ;-D
#!/usr/bin/perl -w use strict; use Benchmark qw(:all); my @rands = qw (A---B-B---B---D----F----G----H----J----K-----L---F-D-- +F---G--H---_R_-f-F-ff-----f ----F----G-- ----F----G------F----G------F----G-- ----F----G------F----G------F----G------F----G-- ----F----G------F----G------F----G------F----G-----F----G--- ----F----G-----F----G--- ----F----G------F----G------F----G--); my $max = @rands; cmpthese(1000000, { 'tr' => sub { $_ = $rands[int(rand($max))]; my $x = tr/-//; }, 'm//' => sub { $_ = $rands[int(rand($max))]; my $x = () = $_ =~ /-/g; }, 'for' => sub { $_ = $rands[int(rand($max))]; my %cnt = (); my @chrs = split '', $_; foreach (@chrs) { $cnt{$_}++; } my $x = $cnt{'-'}; }, } ); __END__ Benchmark: timing 1000000 iterations of for, m//, tr... for: 98 wallclock secs (95.68 usr + 0.09 sys = 95.77 CPU) @ 10 +441.68/s (n=1000000) m//: 55 wallclock secs (53.85 usr + 0.06 sys = 53.91 CPU) @ 18 +549.43/s (n=1000000) tr: 2 wallclock secs ( 1.81 usr + 0.00 sys = 1.81 CPU) @ 55 +2486.19/s (n=1000000) Rate for m// tr for 10442/s -- -44% -98% m// 18549/s 78% -- -97% tr 552486/s 5191% 2878% --


In reply to Re*4: counting regex hits Benchamark by Tomte
in thread counting regex hits by Becky

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.