This runs about 20% faster for me, YMMV:
use strict; use warnings; use Benchmark; my $match_list = 'a/ere,c/ere'; # verification pattern my $markup = 'TY:X{a} X{c}'; # output markup my $attrs = 'TY a=errt c=rrrdd'; # info to check my $tag = 'TY'; # tag name sub first_draft { my %xlist = map{ split('/', $_, 2) } # make list grep{ m'/' } split(',', $match_list); $attrs =~ s/\A$tag //; # clean up for (split (' ', $attrs)) { my ($name, $value) = split('='); # only one attribute of the same name is allowed. if (defined $xlist{$name}) { $xlist{$name} = undef; # this exists now $markup =~ s/X{$name}/$value/g; } else { # fails get nothing and end. $markup = ''; last; } } # not in Benchmark # $markup # ? print $markup # : print 'nope'; } timethese($ARGV[0] || -1, { 1 ? ( 'first_draft' => \&first_draft, ) : (), });
I would expect there to be a more efficient way to set up %xlist but it hasn't occurred to me yet precisely how.
In reply to Re: Speeding up a Perl code. Can it be faster?
by hippo
in thread Speeding up a Perl code. Can it be faster?
by $h4X4_|=73}{
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |