in reply to Speeding up a Perl code. Can it be faster?
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Speeding up a Perl code. Can it be faster? (-50%)
by BrowserUk (Patriarch) on Jun 11, 2016 at 12:27 UTC | |
|
Re^2: Speeding up a Perl code. Can it be faster?
by oiskuu (Hermit) on Jun 11, 2016 at 15:49 UTC |