Re: Transform hash key?



>>>>> "ASU" == A Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx> writes:

ASU> my %h = map { $_ => 1 } ('aaa' .. 'zzz');

ASU> cmpthese -1, {
ASU> map => sub { %h = map { uc $_ => $h{$_} } keys %h },
ASU> for => sub { $h{uc $_} = delete $h{$_} for keys %h; },
ASU> };

this benchmark has a common problem in that you don't set up the hash
the same way for each run. the first time you call either sub, the hash
will have only upper case keys. now i doubt that uc will be faster or
slower given any mix of input case but it still is wrong. if the
transform were something whose speed was data dependent, this benchmark
would be very bogus.

the map one could be fixed just by assigning it to a different hash. the
for one would need a fresh hash each time as it modifies it in place. so
you would need to do the same work for each one and my best idea would
be to copy the %h to %h2 inside each sub and use that as the input (and
you can use it for the output of the map. also choosing a different
output hash for the map could affect speed as well.

this is just a small lesson on the difficulty of properly benchmarking
apples and apples.

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.



Relevant Pages

  • Re: Transform hash key?
    ... >> this benchmark has a common problem in that you don't set up the hash ... ASU> I actually thought about this before posting. ... >> the map one could be fixed just by assigning it to a different hash. ... ASU> use Benchmark qw; ...
    (comp.lang.perl.misc)
  • Re: Writing a Compiler: Lisp or Scheme or Haskell?
    ... the occurences of various longer subsequences. ... I guess my problem with this particular benchmark is that it doesn't ... seem like a particularly good application of a Hash table. ... We aren't really measuring hash-table look-up time with this ...
    (comp.lang.lisp)
  • Re: Transform hash key?
    ... > this benchmark has a common problem in that you don't set up the hash ... > this benchmark would be very bogus. ... > the map one could be fixed just by assigning it to a different hash. ... use Benchmark qw(cmpthese); ...
    (comp.lang.perl.misc)
  • RE: Hash & CSV
    ... Dumper is taking more time for my 10000 lines of CSV file. ... Subject: Hash & CSV ... How to find the performance and time taken by Perl script? ... For benchmarking the perl scripts you can use the Benchmark module. ...
    (perl.beginners)
  • Re: Page cache using B-trees benchmark results
    ... > I am attaching the benchmark results for Page Cache Implementation ... > against my kernel (with the B-tree implementation) and the Linux ... hash tables in the kernel that might benefit from trying ...
    (Linux-Kernel)