in reply to "exists $hash{key}" is slower than "$hash{key}"
Just a very wild guess (Disclaimer: I didn't check your benchmark for possible holes)
It seems to me that exists is just implemented on top of retrieving the value.
IOW the opcode for exists gets the value but throws it away, which makes it more expensive than a normal look-up.
C:\WINDOWS\system32>perl -MO=Concise -E"exists $h{a}" 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 74 -e:1) v:%,{,469764096 ->3 - <1> ex-exists vK/1 ->4 3 <+> multideref($h{"a"}) vK/EXISTS ->4 - <0> ex-gv s ->3 -e syntax OK C:\WINDOWS\system32>perl -MO=Concise -E"$h{a}" 4 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 74 -e:1) v:%,{,469764096 ->3 - <1> ex-helem vK/2 ->4 3 <+> multideref($h{"a"}) vK ->4 - <0> ex-gv s ->3 -e syntax OK
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: "exists $hash{key}" is slower than "$hash{key}"
by swl (Prior) on Jan 06, 2020 at 00:57 UTC | |
by LanX (Saint) on Jan 06, 2020 at 01:18 UTC | |
by swl (Prior) on Jan 07, 2020 at 00:52 UTC | |
by LanX (Saint) on Jan 07, 2020 at 01:45 UTC | |
by swl (Prior) on Jan 07, 2020 at 03:15 UTC | |
|