Assembler programmers wouldn't program in Perl.
The mindset is indeed important. And it's very important to program in a language that fits ones mindset. If your mindset is that microseconds are important, Perl is the wrong language for you.
As for the actual differences:
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark 'cmpthese';
our @array = (1 .. 1000);
foreach my $x (1 .. 10) {
cmpthese -1, {
alias => 'my $c = 0; foreach (@array) {$c += $_}',
variable => 'my $d = 0; foreach my $var (@array) {$d += $var}'
+,
};
}
__END__
Rate alias variable
alias 3139/s -- -3%
variable 3230/s 3% --
Rate alias variable
alias 3139/s -- -2%
variable 3199/s 2% --
Rate alias variable
alias 3139/s -- -0%
variable 3140/s 0% --
Rate alias variable
alias 3140/s -- -0%
variable 3143/s 0% --
Rate alias variable
alias 3110/s -- -5%
variable 3262/s 5% --
Rate alias variable
alias 3083/s -- -5%
variable 3229/s 5% --
Rate alias variable
alias 3131/s -- -3%
variable 3229/s 3% --
Rate alias variable
alias 3083/s -- -5%
variable 3229/s 5% --
Rate variable alias
variable 2821/s -- -10%
alias 3140/s 11% --
Rate alias variable
alias 3140/s -- -2%
variable 3200/s 2% --
You'd need to do some very careful analysis before deciding which of the two will save you some micro-seconds. Your analysis isn't based on anything. Just because something isn't in the code doesn't mean it isn't done. |