There is a significant time difference between methods 1 and 2 which is presumably because of the inner loop encoded explicitly in perl in method (2) vs the implicit inner loop in method (1) actually implemented in C.

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Time::HiRes qw(time); use Data::Dump qw(dump pp); my %checkFrom; my @toCheck; sub init0() {@toCheck = (); push @toCheck, rand(1e6) for 1..1e4; } sub init1() {%checkFrom = (); for my $x(0..999) {for my $y(0..999) {$checkFrom{$x}[$y] = 1e3*$x+$y; } } init0(); } sub init2() {%checkFrom = (); for my $x(0..999) {for my $y(0..999) {$checkFrom{$x}{$y} = 1e3*$x+$y; } } init0(); } for(1..10) {if (1) {init1(); my $s = time(); {my %toCheck = map { $_ => 1 } @toCheck; @$_ = grep !$toCheck{$_}, @$_ for values %checkFrom; } say "1 took ", (time() - $s); } if (2) {init2(); my $s = time(); {for my $thing (@toCheck) {for my $category (keys %checkFrom) {delete $checkFrom{$category}{$thing}; } } } say "2 took ", (time() - $s); } }

Produces

1 took 1.06206107139587
2 took 11.8416769504547
1 took 1.10106301307678
2 took 12.3792278766632
1 took 1.07640194892883
2 took 12.4490790367126
1 took 1.2350709438324
2 took 12.7647299766541
1 took 1.27407312393188
2 took 12.8677358627319
1 took 1.17906808853149
2 took 12.6504328250885
1 took 1.17000198364258
2 took 12.8158860206604
1 took 1.2890739440918
2 took 12.8577361106873
1 took 1.32807612419128
2 took 12.7377278804779
1 took 1.24107122421265
2 took 12.7136778831482

In reply to Re: Removal of values in array from array list by philiprbrenan
in thread Removal of values in array from array list by jemswira

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.