toforeach my $k (keys %h){ }
, benchmark shows while/each becomes fasterforeach my $k (keys %h){ my $v=$h{$k}; }
case 10000 hash ready ... count=10000 Sat Nov 12 01:13:29 2011 ---------------------------------------- Rate test_each test_keys test_each 108/s -- -28% test_keys 151/s 40% -- ---------------------------------------- Sat Nov 12 01:14:22 2011 case 100000 hash ready ... count=100000 Sat Nov 12 01:14:23 2011 ---------------------------------------- Rate test_keys test_each test_keys 4.63/s -- -23% test_each 6.02/s 30% -- ---------------------------------------- Sat Nov 12 01:15:20 2011 case 1000000 hash ready ... count=1000000 Sat Nov 12 01:15:32 2011 ---------------------------------------- s/iter test_keys test_each test_keys 2.71 -- -30% test_each 1.89 43% -- ---------------------------------------- Sat Nov 12 01:16:35 2011 case 2000000 hash ready ... count=2000000 Sat Nov 12 01:19:32 2011 ---------------------------------------- s/iter test_keys test_each test_keys 5.69 -- -31% test_each 3.91 46% -- ---------------------------------------- Sat Nov 12 01:21:49 2011
It seems I miss something with GTop.$./025-6.pl -M1=keys -M2=pairs -N=1e6 hash built, starting timer Took 3.931463 and 39.000MB extra memory for 1000000 using keys/pairs m +ethod $./025-6.pl -M1=each -M2=pairs -N=1e6 hash built, starting timer Took 2.434757 and 1.000MB extra memory for 1000000 using each/pairs me +thod
In reply to Re^10: Finding the size of a nested hash in a HoH
by remiah
in thread Finding the size of a nested hash in a HoH
by Jeri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |