Clear questions and runnable code
get the best and fastest answer
Does eval cause that much of a performance hit?by sherab (Beadle)
|on May 06, 2009 at 02:40 UTC||Need Help??|
sherab has asked for the
wisdom of the Perl Monks concerning the following question:
Hello brothers and sisters,
I have recently started a new job developing perl with some definite perl advocates but they tend to be older guys and prefer things like a three line if construct than a trailing if.
That being said, I'm certainly no perl expert, but I have discovered a technique that I enjoy. The technique revolves around situations when a number of tests need to be conducted.
My technique is to place tests into either a hash or array and then eval them via map.
The criticism I get is that eval causes a performance hit that may not be worth it. I have been called out on a couple of issues that later proved to be correct on my part so I tend to verify everything now.
If I have a series of 15 tests I have to perform, I would much prefer to put the 15 tests in a hash, iterate over the keys and do that instead of writing 45 lines of ......
I also just find this way to be plain easier to add new tests if need be.
Should I really be concerned about performance hits? Does eval REALLY cause that much of a performance issue?