Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by rsFalse (Chaplain)
on May 19, 2018 at 12:02 UTC ( [id://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.
edited

Replies are listed 'Best First'.
Re^2: '%hash = ()' is slower than 'undef %hash'
by rsFalse (Chaplain) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found