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

For anything but small hashes, the total time will be dominated by the time to free all the hash elements (which uses the same code path for both methods). Other than that, the assign will generally have a slightly higher overhead as it has to create an empty list first. In perl 5.26.0, the actual list assign operator has been optimised so that it handles an empty RHS lists more efficiently.

Dave.

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