in reply to Re: Re: Performance of Perl references
in thread Performance of Perl references
Benchmark: timing 100000 iterations of multiple_indirection, reduced_indirection...
multiple_indirection: 29 wallclock secs (28.08 usr + 0.00 sys = 28.08 CPU) @ 3561.25/s (n=100000)
reduced_indirection: 25 wallclock secs (24.19 usr + 0.00 sys = 24.19 CPU) @ 4133.94/s (n=100000)
Rate multiple_indirection reduced_indirection
multiple_indirection 3561/s -- -14%
reduced_indirection 4134/s 16% --
-- O thievish Night, Why should'st thou, but for some felonious end, In thy dark lantern thus close up the stars? --Milton#!/usr/bin/perl my %innerdata; @innerdata{a..z} = a..z; my $data = { foo => { %innerdata }, bar => { %innerdata } }; sub foo { my $data = $_[0]; for $key1 (keys %$data) { for $key2 (keys %{$data->{$key1}}) { my $val = $data->{$key1}->{$key2}; # process $val; # print $val; } } } sub bar { my $data = $_[0]; for $key1 (keys %$data) { my $data2 = $data->{$key1}; for $key2 (keys %$data2) { my $val = $data2->{$key2}; # process $val; # print $val; } } } use Benchmark qw(cmpthese); cmpthese( 100000, { multiple_indirection => sub { foo($data) }, reduced_indirection => sub { bar($data) }, } )
|
|---|