Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Dereferencing in blessed object

by bliako (Monsignor)
on Feb 26, 2021 at 12:25 UTC ( [id://11128827]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dereferencing in blessed object
in thread Dereferencing in blessed object

$$vars{'test'} is a visual pain for me because of the split millisecond where I ask myself about precedence. OTH the -> in $vars->{'test'} dates back to at least C where is used in exactly the same way and context.

Performance-wise I don't think there is a difference (OSX 10.13 and perl 5.28.3):

use Benchmark qw( cmpthese ); cmpthese(-5, { deref => 'use strict; use warnings; my $x = { map { $_ => rand + } 1..50 }; $x->{$_} = $_ for 1..100', none => 'use strict; use warnings; my $x = { map { $_ => rand + } 1..50 }; $$x{$_} = $_ for 1..100' }); Rate deref none deref 12483/s -- -1% none 12611/s 1% -- Rate none deref none 11938/s -- -0% deref 11967/s 0% --

Or,

use Benchmark qw( cmpthese ); cmpthese(-5, { deref => 'use strict; use warnings; srand 42; my $x = { map { rand() => rand() } 1..50 }; srand 42; $x->{rand()} = rand() for 1..100', none => 'use strict; use warnings; srand 42; my $x = { map { rand() => rand() } 1..50 }; srand 42; $$x{rand()} = rand() for 1..100' });

For benchmarks see also: https://stackoverflow.com/questions/18984323/how-expensive-is-it-to-dereference-an-array-ref-in-perl

bw, bliako

Replies are listed 'Best First'.
Re^4: Dereferencing in blessed object
by LanX (Saint) on Feb 26, 2021 at 12:48 UTC
    > Performance-wise I don't think there is a difference (OSX 10.13 and perl 5.28.3):

    That would be surprsing, it's compiled to the same op-code.

    C:\WINDOWS\System32>perl -MO=Deparse -e"$$x{key}" $x->{'key'}; -e syntax OK C:\WINDOWS\System32>perl -MO=Concise -e"$$x{key}" 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter v ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 - <1> ex-helem vK/2 ->4 3 <+> multideref($x->{"key"}) vK ->4 - <0> ex-gv s ->3 -e syntax OK C:\WINDOWS\System32>perl -MO=Concise -e"$x->{key}" 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter v ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 - <1> ex-helem vK/2 ->4 3 <+> multideref($x->{"key"}) vK ->4 - <0> ex-gv s ->3 -e syntax OK C:\WINDOWS\System32>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Good point!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found