NAME
Bencher::Scenario::ModuleInstalledTiny::module_installed - Benchmark module_installed() vs some others
VERSION
This document describes version 0.004 of Bencher::Scenario::ModuleInstalledTiny::module_installed (from Perl distribution Bencher-Scenarios-ModuleInstalledTiny), released on 2020-01-14.
SYNOPSIS
To run benchmark with default option:
% bencher -m ModuleInstalledTiny::module_installed
To run module startup overhead benchmark:
% bencher --module-startup -m ModuleInstalledTiny::module_installed
For more options (dump scenario, list/include/exclude/add participants, list/include/exclude/add datasets, etc), see bencher or run bencher --help.
DESCRIPTION
This scenario benchmarks module_installed() vs some others for the task of checking whether a module "is available locally". There are several approaches (also described in Module::Installed::Tiny documentation):
- 1. require() it (executes module source code, security and resource concern).
 - 2. find module path in filesystem using Module::Path (cannot handle hooks/references in @INC; on the other hand does not quickly check %INC first).
 - 3. Module::Load::Conditional's 
check_install(). Likerequire(), it first checks %INC, then scan @INC (hooks/references in @INC are supported). Additionally, you can specify a version number, in which case it will also use Module::Metadata to extract version from module source code. - 4. Module::Installed::Tiny's 
module_installed(), which also does things like Perl'srequire()except actually evaluating the module source code. 
Packaging a benchmark script as a Bencher scenario makes it convenient to include/exclude/add participants/datasets (either via CLI or Perl code), send the result to a central repository, among others . See Bencher and bencher (CLI) for more details.
BENCHMARKED MODULES
Version numbers shown below are the versions used when running the sample benchmark.
Module::Installed::Tiny 0.004
Module::Path::More 0.33
Module::Load::Conditional 0.68
BENCHMARK PARTICIPANTS
Module::Installed::Tiny::module_installed (perl_code)
Function call template:
Module::Installed::Tiny::module_installed(<module>)Module::Path::More::module_path (perl_code)
Function call template:
Module::Path::More::module_path(module => <module>)Module::Load::Conditional::check_install (perl_code)
Function call template:
Module::Load::Conditional::check_install(module => <module>)require (perl_code)
Code template:
eval { (my $pm = <module> . ".pm") =~ s!::!/!g; require $pm; 1 } ? 1:0
BENCHMARK DATASETS
strict
Bencher::Scenario::ModuleInstalledTiny::module_installed::Test
SAMPLE BENCHMARK RESULTS
Run on: perl: v5.30.0, CPU: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores), OS: GNU/Linux Ubuntu version 19.04, OS kernel: Linux version 5.0.0-37-generic.
Benchmark with default options (bencher -m ModuleInstalledTiny::module_installed):
#table1#
+-------------------------------------------+----------------------------------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant                               | dataset                                                        | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
+-------------------------------------------+----------------------------------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| Module::Load::Conditional::check_install  | strict                                                         |      3300 |  300      |                 0.00% |            155352.19% | 1.2e-06 |      20 |
| Module::Load::Conditional::check_install  | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test |     40000 |   25      |              1112.29% |             12722.99% | 2.7e-08 |      20 |
| Module::Path::More::module_path           | strict                                                         |     60100 |   16.6    |              1711.19% |              8482.85% | 6.2e-09 |      23 |
| Module::Path::More::module_path           | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test |     61400 |   16.3    |              1749.98% |              8302.89% | 5.8e-09 |      26 |
| require                                   | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test |     70000 |   14      |              2023.32% |              7221.19% | 2.7e-08 |      20 |
| Module::Installed::Tiny::module_installed | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test |     85000 |   12      |              2471.21% |              5945.88% | 1.3e-08 |      21 |
| Module::Installed::Tiny::module_installed | strict                                                         |   2032000 |    0.4922 |             61166.01% |               153.73% | 2.3e-11 |      20 |
| require                                   | strict                                                         |   5160000 |    0.194  |            155352.19% |                 0.00% | 8.7e-11 |      31 |
+-------------------------------------------+----------------------------------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Benchmark module startup overhead (bencher -m ModuleInstalledTiny::module_installed --module-startup):
#table2#
+---------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
| participant               | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
+---------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
| Module::Load::Conditional |     31.1  |             24.2  |                 0.00% |               349.93% | 2.6e-05   |      20 |
| Module::Path::More        |     10    |              3.1  |               199.48% |                50.24% |   0.00015 |      20 |
| Module::Installed::Tiny   |      9.43 |              2.53 |               229.74% |                36.45% | 7.6e-06   |      20 |
| perl -e1 (baseline)       |      6.9  |              0    |               349.93% |                 0.00% | 3.2e-05   |      20 |
+---------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
To display as an interactive HTML table on a browser, you can add option --format html+datatables.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Bencher-Scenarios-ModuleInstalledTiny.
SOURCE
Source repository is at https://github.com/perlancar/perl-Bencher-Scenario-ModuleInstalledTiny.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Bencher-Scenarios-ModuleInstalledTiny
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2020, 2017, 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.