Very true, @robzilla, but I know me :-/ I do the wide majority of these updates between 2 and 4am, and there have been more than a few times that this double-check saved my butt! LOL 8-9 hours of downtime can mean a loss of $75-100, not to mention long term loss of new users. So it's like @lucy24 said: it's a waste of time, until it's not. I'd rather have a double-check in place than risk it.
I was hoping that there was a faster way to double check, but I guess not :-(
I did a benchtest on jdoodle.com, though, and found that DO is marginally faster on a FAIL in this scenario. I tested using 'random.lib', which (I assume) doesn't exist on jdoodle, so if it did exist then it might be faster.
BUT! When the test succeeds, the DO has a second REQUIRE, while the EVAL does not. So since I expect a success considerably more often than a fail, the combination of the DO and REQUIRE would probably end up being slower than the single EVAL.
So for my purposes, I'm going to stick with EVAL unless someone can suggest a third option.
It's also notable that when I did a simple math equation (eg,
do '$x = 14 * 12'), EVAL was MUCH faster! Like 100 times faster.
Here's my test:
# using Perl v. 5.22.0
use Time::HiRes qw(gettimeofday);
# Test 1: 0.196840047836304
$start_time = microtime(TRUE);
for ($i = 0; $i < 10000; $i++) {
do 'random.lib';
}
$end_time = microtime(TRUE);
print 'Test 1: ';
print ($end_time - $start_time);
print "\n";
# Test 2: 0.254052877426147
$start_time = microtime(TRUE);
for ($i = 0; $i < 10000; $i++) {
eval { require 'random.lib' };
}
$end_time = microtime(TRUE);
print 'Test 2: ';
print ($end_time - $start_time);
I have a microtime() function that I borrowed from somewhere that's in the script, too. I didn't post it for the sake of brevity, but I can upon request.