http://qs321.pair.com?node_id=11111265


in reply to Re^9: "exists $hash{key}" is slower than "$hash{key}"
in thread "exists $hash{key}" is slower than "$hash{key}"

Thanks once again.

Changing the my %hash line to our %hash makes the results much more variable, with exists being fastest about half the time across ten runs.

If the Porting/bench.pl tool shows fewer instructions, branches etc. for exists then I'll take that as being a more authoritative test.

For future readers, adding an explicit use warnings; to the script does not raise any warnings with the lexical hash in the benchmark code. Benchmark.pm does not use warnings and explicitly disables strict when evaling strings of benchmark code (see sub _doeval in the code). String-form benchmark code might avoid sub overheads, but more care needs to be taken with the code.

For purposes of posterity, the compilers used to compile the perls I used were gcc 7.1.0 for Strawberry perl on Windows, and gcc 6.2.0 on linux.