http://qs1969.pair.com?node_id=11141665


in reply to Re: Performance issue in the loop.
in thread Performance issue in the loop.

Moar PDL!

Here's my tweak of vr's excellent code, for use in the perldl REPL, which doesn't feature the check, just does timing (and doesn't use strict because of the REPL), and uses "+=" instead of the wordier "->inplace->plus":

$n = 2e4; @input = map int rand 1e5, 1 .. $n; $sums = zeroes long, scalar @input; $vec = pdl long, \@input; with_time { my @max = map +($sums( 0 : -$_ - 1 ) += $vec( $_ : -1 ))-> +maximum, 0 .. $#input };
I also increased the $n.

EDIT: in PDL 2.077 with_time is always available in the PDL shells so I removed the definition of it here.