in reply to Re^5: schwartzian transform problem
in thread schwartzian transform problem - Solved
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 needcmpthese( -1, { 'a' => GRT($s), 'b' => ST($s) } ) ;
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: schwartzian transform problem
by Cristoforo (Curate) on Mar 24, 2025 at 16:38 UTC | |
by ikegami (Patriarch) on Mar 25, 2025 at 23:02 UTC | |
by Anonymous Monk on Mar 26, 2025 at 22:21 UTC |