in reply to Match speed of R in array procesing
You don't say how big your arrays are, but once the data is generated, this script takes just over 3/4 of a second to index 1,000,000 items (array_1) and then to process 100,000 items (array_1) against that index; deleting 198 items from the two arrays:
#! perl -slw use strict; use Time::HiRes qw[ time ]; our $A //= 1e6; our $B //= 1e5; my @alphas = 'aaa'..'zzz'; my @numers = '0'..'9'; print "Gening data..."; my @a = map{ $alphas[ rand @alphas] . $numers[rand @numers] } 1 .. $A; my @b = map{ $alphas[ rand @alphas] . $numers[rand @numers] } 1 .. $B; my @c = 1 .. @b; print "Starting..."; my $start = time; print "Indexing..."; ## index array @a my %a; undef $a{ $_ } for @a; print "Removing..."; for my $i ( reverse 0 .. $#b ) { exists $a{ $b[ $i ] } and delete $b[$i] and delete $c[$i]; } printf "Took %.6f seconds to check %d (\@b) against %d (\@a) and remov +e %d items\n", time() - $start, $B, $A, $B - @b __END__ C:\test>962209 -A=1e6 -B=1e5 Gening data... Starting... Indexing... Removing... Took 0.771435 seconds to check 100000 (@b) against 1000000 (@a) and re +move 198 items
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match speed of R in array procesing
by Anonymous Monk on Mar 28, 2012 at 17:41 UTC |