PDL 2.021: perl -d:NYTProf demo_win.pl 1e7 # 5.238 secs.
PDL 2.079: perl -d:NYTProf demo_win.pl 1e7 # 9.511 secs.
####
Calls P F ExTime InTime Subroutine
61776 1 1 186ms 186ms File::Which::CORE::regcomp (opcode)
18 2 1 119ms 394ms File::Which::which
5616 1 1 66.6ms 66.6ms File::Which::CORE:ftdir (opcode)
61776 1 1 15.9ms 15.9ms File::Which::CORE:match (opcode)
5616 1 1 800µs 800µs File::Which::CORE:fteexec (opcode)
5148 1 1 668µs 668µs File::Which::CORE:ftis (opcode)
####
File::Map 0.67
MCE 1.878
####
use strict;
use warnings;
use feature 'say';
use PDL;
use Time::HiRes 'time';
{
no warnings 'once'; $PDL::BIGPDL = 1;
eval q{ PDL::set_autopthread_targ(1) };
}
use constant MAX => shift || 500000;
use constant MAXLEN => MAX * 1;
my $t = time;
my $lengths = ones( short, 3 + MAXLEN );
$lengths-> inplace-> setvaltobad( 1 );
$lengths-> set( 1, 1 );
$lengths-> set( 2, 2 );
$lengths-> set( 4, 3 );
my ($from, $to) = (0, MAX);
my $seqs_c = $from + sequence( longlong, $to - $from + 1 );
$seqs_c-> setbadat( 0 );
$seqs_c-> setbadat( 1 );
$seqs_c-> badvalue( 2 );
my $lengths_c = $lengths-> slice([ $from, $to ]);
my $current = zeroes( short, nelem( $seqs_c ));
while ( any $seqs_c-> isgood ) {
my ( $seqs_c_odd, $current_odd_masked )
= where( $seqs_c, $current, $seqs_c & 1 );
$current_odd_masked ++;
$current ++;
( $seqs_c_odd *= 3 ) ++;
$seqs_c >>= 1;
my ( $seqs_cap, $lengths_cap, $current_cap )
= where( $seqs_c, $lengths_c, $current,
$seqs_c <= MAXLEN );
my $lut = $lengths-> index( $seqs_cap );
# "_f" is for "finished"
my ( $seqs_f, $lengths_f, $lut_f, $current_f )
= where( $seqs_cap, $lengths_cap, $lut, $current_cap,
$lut-> isgood );
$lengths_f .= $lut_f + $current_f;
$seqs_f .= 2; # i.e. BAD
}
say {*STDERR} time - $t;
####
$PDL::BIGPDL = 1;
PDL 2.021: perl test.pl 2e6 # 4.590 secs.
PDL 2.079: perl test.pl 2e6 # 7.252 secs.
# $PDL::BIGPDL = 1; # line commented out
PDL 2.021: perl test.pl 2e6 # 4.490 secs.
PDL 2.079: perl test.pl 2e6 # 5.252 secs.