in reply to Re^7: Do you really want to use an array there?
in thread Do you really want to use an array there?
Ok. Here you go:
#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $packedV = pack 'V*', 1 .. 1e6; our $packedW = pack 'w*', 1 .. 1e6; our $packedVec = ''; vec( $packedVec, $_, 32 ) = $_ for 0 .. 1e6 - 1; cmpthese -5, { unpackV => q[ my @nums = unpack 'V*', $packedV; ], unpackW => q[ my @nums = unpack 'w*', $packedW; ], unVec => q[ my @nums; push @nums, vec( $packedVec, $_, 32 ) for 0 .. 1e6 - + 1 ], }; print "$_: ", length( do{ no strict; ${$_} } ) for qw[ packedV packedW packedVec ]; __END__ C:\test>junk0 Rate unVec unpackV unpackW unVec 1.87/s -- -29% -31% unpackV 2.64/s 41% -- -2% unpackW 2.70/s 44% 2% -- packedV: 4000000 packedW: 2983490 packedVec: 4000000
unpack 'w' is 44 % faster than vec and compresses the data to 75% to boot. Which means less time to transfer from the DB.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Do you really want to use an array there?
by MimisIVI (Acolyte) on Apr 14, 2008 at 18:37 UTC | |
by MimisIVI (Acolyte) on Apr 14, 2008 at 20:43 UTC | |
by MimisIVI (Acolyte) on Apr 16, 2008 at 20:12 UTC |