in reply to Re^3: [OT] Swapping buffers in place.
in thread [OT] Swapping buffers in place.
for odd length of buffers.
My current understanding is that the logic needs to be different for each of 4 possibilities:
Also, your approach seems to do considerable more moving/swapping than is optimal; and Perl's convenient-but-slow:
cmpthese -1, { a => q[ my @a = 1 .. 1e5; @a[ $_, $_+2 ] = @a[ $_+2, $_ ] for 0 .. $#a-2 ], b => q[ my( @a, $t ) = 1 .. 1e5; $t = $a[ $_ ], $a[ $_ ] = $a[ $_+2 ], $a[ $_+2 ] = $t for 0 .. + $#a-2 ] };; Rate a b a 9.65/s -- -13% b 11.1/s 15% --
array-slice to array-slice assignment, hides a lot of sins.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: [OT] Swapping buffers in place.
by hdb (Monsignor) on Mar 01, 2015 at 14:57 UTC | |
by BrowserUk (Patriarch) on Mar 01, 2015 at 18:01 UTC | |
by hdb (Monsignor) on Mar 01, 2015 at 18:09 UTC | |
by BrowserUk (Patriarch) on Mar 01, 2015 at 18:35 UTC |