I was pleasantly surprised today to discover that any, all (and also or, etc.) now short-circuit properly.
With one of previous versions (it was the same with 2.085, which I don't have already):
Loaded PDL v2.084
pdl> $x = zeroes byte, 1e9
pdl> $a = copy $x; set $a, 0, 1
pdl> $z = copy $x; set $z, -1, 1
pdl> help vars
PDL variables in package main::
Name Type Dimension Flow State Mem
----------------------------------------------------------------
$a Byte D [1000000000] P 953.67MB
$x Byte D [1000000000] P 953.67MB
$z Byte D [1000000000] P 953.67MB
pdl> with_time { print $x-> any, ' ' } for 1..3
0 1567.51 ms
0 1498.09 ms
0 1505.89 ms
pdl> with_time { print $a-> any, ' ' } for 1..3
1 970.624 ms
1 941.319 ms
1 940.539 ms
pdl> with_time { print $z-> any, ' ' } for 1..3
1 1489.67 ms
1 1510.22 ms
1 1468.07 ms
pdl>
"$a" case is somewhat faster, but shouldn't it be instant instead of almost a second? Now let's see with current release:
Loaded PDL v2.088
pdl> $x = zeroes byte, 1e9
pdl> $a = copy $x; set $a, 0, 1
pdl> $z = copy $x; set $z, -1, 1
pdl> help vars
PDL variables in package main::
Name Type Dimension Flow State Mem
----------------------------------------------------------------
$a Byte D [1000000000] P 953.67MB
$x Byte D [1000000000] P 953.67MB
$z Byte D [1000000000] P 953.67MB
pdl> with_time { print $x-> any, ' ' } for 1..3
0 783.335 ms
0 749.517 ms
0 756.531 ms
pdl> with_time { print $a-> any, ' ' } for 1..3
1 0.103 ms
1 0.091 ms
1 0.092 ms
pdl> with_time { print $z-> any, ' ' } for 1..3
1 748.246 ms
1 741.717 ms
1 739.352 ms
pdl>
Not only $x and $z cases are twice as fast, but the $a case short-circuits indeed. I don't see this improvement mentioned in what's new (is it somewhat vague "PP add loop(n=start:end:inc) idiom to stop not at end and have non-1 inc"?); changes like this should be heralded in city squares, no less :-). Very good work!
|