Thank you all for help and showing me more ways to do the same thing faster.
From tweaking this small code I managed to speed it up about three times faster, just moving some stuff around.
Test output:sub forth_draft { my %xlist = map{ split('\/', $_) } split(',', $match_list); $attrs =~ s/\A$tag //; # clean up for (split (' (?=\w+\=)', $attrs)) { my ($name, $value) = split('='); # little more golfing action (defined $xlist{$name} && $markup =~ s/X\{$name\}/$value/g) ? $xlist{$name} = undef # this exists now : $markup = '' if $markup; # do this and let it run through, fas +ter. last if !$markup; # with out this it drops speed now? } # not in Benchmark # $markup # ? print $markup # : print 'nope'; }
Benchmark: running a_first_draft, b_second_draft, c_third_draft, d_for +th_draft for at least 1 CPU seconds... a_first_draft: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ + 29132.76/s (n=30502) b_second_draft: 1 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU) +@ 31449.73/s (n=34406) c_third_draft: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ + 35255.18/s (n=39098) d_forth_draft: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ + 115597.37/s (n=122880)
In reply to Re: Speeding up a Perl code. Can it be faster?
by $h4X4_|=73}{
in thread Speeding up a Perl code. Can it be faster?
by $h4X4_|=73}{
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |