in reply to Experimental features: autoderef vs postfix deref
For anyone interested, I've been doing some basic benching. Two of the tests are self-explanitory. The "no_braces" test is the same as "circumfix", except that it has all but the mandatory bracing removed. Over the next couple days, I'll do more elaborate testing that can be repeated easily. In this case, after numerous runs, I can only suspect that the 'no_braces' is slower consistently because perhaps perl has to do extra work to decide how to proceed. This is only a guess though. I don't know nearly enough about the guts to know for sure.
Result:
Rate no_braces circumfix postderef no_braces 2.59/s -- -2% -7% circumfix 2.64/s 2% -- -5% postderef 2.78/s 7% 5% --
Benchmark code:
#!/usr/bin/perl use warnings; use strict; use feature 'postderef'; no warnings 'experimental::postderef'; use Benchmark qw(cmpthese timethese); my $count = 100000; cmpthese(1000, { 'circumfix' => \&circumfix, 'postderef' => \&postderef, 'no_braces' => \&no_braces, }); sub circumfix { my ($h, $a, @a); for (1..$count){ push @{$h->{$_}}, [$_]; } for my $k (keys %{$h}){ for (@{$h->{$k}}){ push @{$a}, $_ for @{$_}; } } push @a, $_ for @{$a}; } sub postderef { my ($h, $a, @a); for (1..$count){ push $h->{$_}->@*, [$_]; } for my $k (keys $h->%*){ for ($h->{$k}->@*){ push $a->@*, $_ for $_->@*; } } push @a, $_ for $a->@*; } sub no_braces { my ($h, $a, @a); for (1..$count){ push @{$h->{$_}}, [$_]; } for my $k (keys %$h){ for (@{$h->{$k}}){ push @$a, $_ for @$_; } } push @a, $_ for @$a; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Experimental features: autoderef vs postfix deref
by shmem (Chancellor) on Jul 13, 2015 at 20:41 UTC | |
by stevieb (Canon) on Jul 13, 2015 at 20:54 UTC | |
Re^2: Experimental features: autoderef vs postfix deref
by BrowserUk (Patriarch) on Jul 13, 2015 at 20:08 UTC | |
by stevieb (Canon) on Jul 13, 2015 at 20:59 UTC | |
by BrowserUk (Patriarch) on Jul 13, 2015 at 21:37 UTC | |
by stevieb (Canon) on Jul 13, 2015 at 21:53 UTC | |
| |
by stevieb (Canon) on Jul 13, 2015 at 22:12 UTC |