#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use Benchmark qw{ cmpthese }; my %hl; @hl{1001 .. 2000} = (1) x 1000; our %hg = %hl; our ($el, $vl, $eg, $vg) = (0) x 4; die unless $hl{1001}; die unless $hg{1001}; cmpthese(-1, { exist_l => q{ ++$el if exists $hl{1001} }, value_l => q{ ++$vl if $hl{1001} }, exist_g => q{ ++$eg if exists $hg{1001} }, value_g => q{ ++$vg if $hg{1001} }, }); say join "\n", "el: $el", "vl: $vl", "eg: $eg", "vg: $vg"; #### Rate value_g exist_g value_l exist_l value_g 17625636/s -- -4% -47% -53% exist_g 18303545/s 4% -- -45% -51% value_l 33363781/s 89% 82% -- -11% exist_l 37417325/s 112% 104% 12% -- el: 0 vl: 0 eg: 23229990 vg: 23229990 #### Rate value_g exist_g value_l exist_l value_g 31977080/s -- -2% -8% -19% exist_g 32733979/s 2% -- -6% -17% value_l 34737228/s 9% 6% -- -12% exist_l 39658833/s 24% 21% 14% --