[Israel.pm] scalars and arrays

Yosef Meller mellerf at netvision.net.il
Sun Feb 15 13:27:40 PST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yaakov Belch wrote:
|>
|>
|> Is there any performance penalty using the wrong syntax ? Yossi
|>
|>
| I would expect some penalty.  I asked my computer:
|
| time perl -we '$a[1]=1 while(++$i<1000000)' time perl -we '@a[1]=1
| while(++$i<1000000)'
|
| You have to run these commands a few times because the first run is
| slower that the following runs (The operating system caches recently
| accessed files).  On my machine, I got 1.020s user time for the first
| example and 1.590s user time for the second example.
|

Considering that the second example is equivalent to ($a[1])=(1), and
actually uses list assignment instead of simple scalar assignment, it
must take longer.

- --
perl -e'$b=unpack"b*",pack"H*","59dfce2d6b1664d3b26cd9969503";
for(;$a<length$b;$a+=9){print+pack"b8",substr$b,$a,8;}'

My public key:
http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0x3D2CA0A8
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAL+RMaElZPz0soKgRAjVsAKCuSeiTV7WCEwZDpgGtJrPUbZPjHACcCZg5
PvyfBI8MrH3ZCNMazdA1Xbs=
=NZIf
-----END PGP SIGNATURE-----



More information about the Perl mailing list