print scalar @var, "\n";
####
#!/usr/bin/perl -w
use strict;
use Benchmark;
timethese(100, {
'no ref' => sub { my @array = sub1() },
'ref' => sub { my $arref = sub2() },
});
sub sub1 {
my @arry = (0..100000);
return @arry;
}
sub sub2 {
my @arry = (0..100000);
return \@arry;
}
####
Benchmark: timing 100 iterations of no ref, ref...
no ref: 33 wallclock secs (28.19 usr + 0.07 sys = 28.26 CPU) @ 3.54/s (n=100)
ref: 10 wallclock secs ( 9.21 usr + 0.34 sys = 9.55 CPU) @ 10.47/s (n=100)
####
sub new {
my $class = shift;
my $self = {
list => {
a => 'ls',
b => 'pwd',
c => 'date',
},
};
bless $self, $class;
return $self;
}
sub get_list {
my ($self) = @_;
return $self->{'list'};
}
####
sub get_list {
my ($self) = @_;
my %ref = %{ $self->{'list'} };
return \%ref;
}