develooper Front page | perl.perl5.porters | Postings from June 2021

Re: Benchmarking Pure Perl Trim Functions.

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
June 4, 2021 07:41
Subject:
Re: Benchmarking Pure Perl Trim Functions.
Message ID:
20210604074107.GH16703@etla.org
On Thu, Jun 03, 2021 at 07:36:18PM +0000, Nicholas Clark wrote:

> *) For all but 4 lines, "separate" is fastest
> *) Sometimes up to 60000% (ie SIX HUNDRED TIMES)

And after I went to bed I realised that's not a fair comparison. That's
against $naive=~s/\A\s+|\s+\z//g;

So I rewrite your test script to time against the original regex /\s+\z/
implementation, forcing it to be used by adding //a:

                default => sub { $default= $string; $default=~s/\A\s+//a;
$default=~s/\s+\z//a; },
                optimised => sub { $optimised= $string; $optimised=~s/\A\s+//;
$optimised=~s/\s+\z//; },


etc

The special-cased optimisation is at least 100% faster, sometimes 50x

reps  ns  sp        len|   default| optimised     as pct|      loop     as pct| loop_chop     as pct|     loop2     as pct|
-----------------------+----------+---------------------+---------------------+---------------------+---------------------+
   1   1   1          3|  897434.8|+1057610.8     +117.8|  673641.7       75.1|  682353.0       76.0|  607109.1       67.6|
   1   1   2          5|  868965.9|+1034517.3     +119.1|  483976.7       55.7|  503774.6       58.0|  584895.0       67.3|
   1   1   5         11|  901560.8|+1033024.4     +114.6|  283364.7       31.4|  311627.8       34.6|  462322.5       51.3|
   1   1  10         21|  849139.8| +970295.1     +114.3|  162071.1       19.1|  186349.9       21.9|  448332.1       52.8|

I think that there were only 3 where the other approaches beat it:

 100  10   1       1101|   96576.9|  567610.3      587.7|  468825.2      485.4| +571266.6     +591.5|  388806.1      402.6|
1000 100   1     101001|    3291.1|   55748.4     1693.9|   50982.1     1549.1|  +65185.9    +1980.7|   51170.8     1554.8|
1000 100   2     102002|    3290.7|   44181.7     1342.6|   33793.5     1027.0|   45068.0     1369.6|  +49740.8    +1511.6|

and not massively.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About