in reply to Re^4: Use 'use' in foreach
in thread Use 'use' in foreach

use will never load a module more than once. It has built-in checking for that, and I'd be willing to bet (without any evidence at all) that allowing it to perform the check would likely be faster than doing your own.

Also, not all modules will have version information, particularly those that are in-house.

Replies are listed 'Best First'.
Re^6: Use 'use' in foreach
by stevieb (Canon) on Jul 19, 2017 at 13:57 UTC

    I don't know if this actually performs a valid comparison, but:

    use warnings; use strict; use Benchmark qw(timethese); use Module::Load; BEGIN { timethese( 1000000000, { my_use => sub { use Data::Dumper; }, my_check => sub { load Data::Dumper if ! $Data::Dumper::VERSION; } } ); }

    Output:

    perl bench_use.pl Benchmark: timing 1000000000 iterations of my_check, my_use... my_check: 24 wallclock secs (27.21 usr + -0.09 sys = 27.12 CPU) @ 36 +873156.34/s (n=1000000000) my_use: -3 wallclock secs ( 0.92 usr + 0.33 sys = 1.25 CPU) @ 800 +000000.00/s (n=1000000000)