Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created August 17, 2011 14:42
Show Gist options
  • Select an option

  • Save sugar84/1151648 to your computer and use it in GitHub Desktop.

Select an option

Save sugar84/1151648 to your computer and use it in GitHub Desktop.
params to hash vs params to hash_ref
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
sub hash {
my $self = shift;
my %params = @_;
return;
}
sub hash_ref {
my $self = shift;
my $params = {@_};
return;
}
cmpthese(-2, {
hash => sub { hash( "self", first => 1, second => 2, third => 3) },
hash_ref => sub { hash_ref("self", first => 1, second => 2, third => 3) },
});
__END__
perl 5.12.3:
Rate hash hash_ref
hash 198194/s -- -24%
hash_ref 261897/s 32% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment