Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Use 'use' in foreach

by stevieb (Canon)
on Jul 19, 2017 at 13:23 UTC ( [id://1195462]=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-18 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found