The difference between PV and PVIV is so small that i did not notice it in my benchmarks and thought that the numbers are CONVERTED to strings :)Rate PVIV PV IV PVIV 2065/s -- -1% -64% PV 2084/s 1% -- -64% IV 5806/s 181% 179% --
The code of the benchmark is here.
#!/usr/bin/perl use warnings; use strict; use Benchmark qw/:hireswallclock cmpthese/; my @ary = (0..10); #only IV my $len = $#ary; my @ary2 = @ary; my @ary3 =qw/0 1 2 3 4 5 6 7 8 9 10/; #only PV print "ARRAY: @ary2\n"; # IV -> PVIV cmpthese (-3, { 'IV' => sub { foreach my $i (0..$len-1) { foreach my $j ($i+1..$len) { my @permuted = @ary; @permuted[$i, $j] = @permuted[$j, $i]; } } }, 'PVIV' => sub { foreach my $i (0..$len-1) { foreach my $j ($i+1..$len) { my @permuted = @ary2; @permuted[$i, $j] = @permuted[$j, $i]; } } }, 'PV' => sub { foreach my $i (0..$len-1) { foreach my $j ($i+1..$len) { my @permuted = @ary3; @permuted[$i, $j] = @permuted[$j, $i]; } } }, });
In reply to Re^3: Don't treat your numbers as strings, or Interpolation is worse than you might think
by Ieronim
in thread Don't treat your numbers as strings, or Interpolation is worse than you might think
by Ieronim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |