home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!usc!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: How fast is... (was Re: randomize.c)
- Message-ID: <1992Sep3.190504.12797@netlabs.com>
- Date: 3 Sep 92 19:05:04 GMT
- Article-I.D.: netlabs.1992Sep3.190504.12797
- References: <1992Aug31.183903.4143@cirrus.com> <1992Sep1.210332.26149@netlabs.com> <1992Sep2.135055.4659@Warren.MENTORG.COM>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 26
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Sep2.135055.4659@Warren.MENTORG.COM> tal@Warren.MENTORG.COM (Tom Limoncelli) writes:
- : In <1992Sep1.210332.26149@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
- :
- : > ...... Subscripting, however, happens
- : >constantly, so we optimize for that.
- :
- : Are associative arrays optimized? For example, many times I do:
- :
- : if ( $foo{$thing} ne $frob ) {
- : $foo{$thing} += $fratz;
- : }
- :
- : Is there a one-entry cache or does it traverse the hash tables twice?
-
- Well, traverse is perhaps a misleading word, since it usually lands
- right on the entry in question. But it does calculate the hash value
- twice. It doesn't know offhand that the value of $thing hasn't changed
- in the meanwhile. It could be made to. But you lose most of the
- advantage if you have to compare the two strings to find out. The right
- way to do that is to associate the hash value with the string, and
- invalidate it if the string changes. I'll need to redo how scalars
- are stored for Perl 5 anyway, so something like that might sneak in.
- Certainly an evaled string ought to cache its parse tree, and this is
- quite similar.
-
- Larry
-