Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: '%hash = ()' is slower than 'undef %hash'

by rsFalse (Friar)
on May 19, 2018 at 12:02 UTC ( #1214907=note: print w/replies, xml ) Need Help??

in reply to '%hash = ()' is slower than 'undef %hash'

Thank you very much for discussion and benchmarks!

I was simply upsolving a competitive programming problem which had 1000 ms time limit and big tests with undirected graphs (tries). After my solution with %hash = () got a verdict time-limit-exceeded, I tried to find how to optimise it. And it was surprising for me, when I found that my program is running ~20% faster when I change to undef %hash, got verdict accepted in 850 ms on max tests. Both variations didn't influence a correctness of an algorithm, only running time. I used %hash as global (here it didn't influence solving time comparing with declaring with 'my').
I'm happy that in newer versions optimisation took place, as dave_the_m have mension. I thought maybe it is unknown or unoptimized thing.

Replies are listed 'Best First'.
Re^2: '%hash = ()' is slower than 'undef %hash'
by rsFalse (Friar) on May 19, 2018 at 12:29 UTC
    I haven't done benchmark by myself, only compared running times of tests cases on CP platform. Problem. Submitions: >1000 ms, 800 ms (maybe not readable, but here only 16th line differs). Perl 5.20.1.
Re^2: '%hash = ()' is slower than 'undef %hash'
by Anonymous Monk on May 19, 2018 at 12:10 UTC
    Probably determined by whether-or-not garbage collection had been triggered.
      Perl does reference counting, it's always triggered, sundial

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214907]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2019-04-21 04:35 GMT
Find Nodes?
    Voting Booth?
    I am most likely to install a new module from CPAN if:

    Results (110 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!