Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Benchmark 'cmpthese'; cmpthese -1, { map { $_ => \&$_ } 'a' .. 'g' }; sub a {eval 1 for 0 .. 999} {use feature ':5.10'; sub b {eval 1 for 0 .. 999}} {use 5.010; sub c {eval 1 for 0 .. 999}} {no feature ':all'; use feature ':5.10'; sub d {eval 1 for 0 .. 999}} {use feature 'say'; sub e {eval 1 for 0 .. 999}} { no feature 'say'; sub f {eval 1 for 0 .. 999}} {use feature 'say'; no feature 'say'; sub g {eval 1 for 0 .. 999}}
Results:
Rate d b e g f a c d 119/s -- -0% -18% -23% -25% -53% -53% b 119/s 0% -- -18% -23% -25% -53% -53% e 145/s 22% 22% -- -7% -8% -43% -43% g 155/s 30% 30% 7% -- -2% -38% -38% f 158/s 33% 33% 9% 2% -- -37% -37% a 252/s 112% 112% 74% 62% 59% -- -0% c 252/s 112% 112% 74% 63% 59% 0% --
Looks like feature pragma leaves some nasty attribute somewhere if mentioned. String eval is slow as it is already, why make it even slower. Well, partly tongue-in-cheek useless entertainment, but still partly: I used to declare like "c" case, then made a habit of explicitly declaring like e.g. "e"; now what? perfectionist in me urges to return to habits of years long gone. The "d" is there because feature says it should be exactly the same as "c".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A plague on all your features
by tobyink (Canon) on Mar 06, 2023 at 14:19 UTC | |
by ikegami (Patriarch) on Mar 07, 2023 at 00:43 UTC | |
by ikegami (Patriarch) on Mar 07, 2023 at 00:58 UTC | |
by ikegami (Patriarch) on Mar 07, 2023 at 01:04 UTC | |
by ikegami (Patriarch) on Mar 07, 2023 at 01:17 UTC | |
|
Re: A plague on all your features
by ikegami (Patriarch) on Mar 07, 2023 at 00:40 UTC | |
|
Re: A plague on all your features
by Leon Timmermans (Acolyte) on Mar 07, 2023 at 18:40 UTC |