cmpthese( -1, { 'a' => GRT($s), 'b' => ST($s) } ) ;
This calls both GRT and ST just once, and uses their output as the code to eval and benchmark. That's not what we want. Instead, we need
cmpthese(-3, { grt => sub { GRT($s) }, st => sub { ST($s) } });

It still seems that ST is much faster:

Rate grt st grt 2.75/s -- -76% st 11.6/s 320% --

But, notice the regex is different when splitting the string:

split m{(?<!\A)(?=>>>)}, $s # GRT split (/^(?=>>> )/m, $s) # ST

So, let's add a test to verify the results stay correct

use Test::More tests => 1; is GRT($s), ST($s), 'same';

and we can use the simpler regex from ST in GRT. Fortunately, the test remains successful, and the results are now different:

1..1 ok 1 - same Rate st grt st 11.7/s -- -3% grt 12.1/s 3% --

An insignificant difference, but at least ST doesn't seem to be much faster now.

Benchmarking and optimisation are hard.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re^6: schwartzian transform problem by choroba
in thread schwartzian transform problem - Solved by Cristoforo

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.