NAME
Bencher::Scenario::ModuleInstalledTiny::module_installed - Benchmark module_installed() vs some others
VERSION
This document describes version 0.003 of Bencher::Scenario::ModuleInstalledTiny::module_installed (from Perl distribution Bencher-Scenarios-ModuleInstalledTiny), released on 2020-01-09.
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) | vs_slowest | errors | samples |
+-------------------------------------------+----------------------------------------------------------------+-----------+-----------+------------+---------+---------+
| Module::Load::Conditional::check_install | strict | 2400 | 420 | 1 | 6.9e-07 | 20 |
| Module::Load::Conditional::check_install | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test | 28000 | 36 | 12 | 3.1e-07 | 21 |
| Module::Path::More::module_path | strict | 44000 | 23 | 18 | 5.3e-08 | 20 |
| Module::Path::More::module_path | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test | 44000 | 23 | 18 | 1.4e-07 | 20 |
| require | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test | 50000 | 20 | 21 | 2.7e-08 | 20 |
| Module::Installed::Tiny::module_installed | Bencher::Scenario::ModuleInstalledTiny::module_installed::Test | 62300 | 16 | 26 | 6.7e-09 | 20 |
| Module::Installed::Tiny::module_installed | strict | 1410000 | 0.708 | 590 | 2.1e-10 | 20 |
| require | strict | 3736000 | 0.2677 | 1561 | 1.2e-11 | 20 |
+-------------------------------------------+----------------------------------------------------------------+-----------+-----------+------------+---------+---------+
Benchmark module startup overhead (bencher -m ModuleInstalledTiny::module_installed --module-startup
):
#table2#
+---------------------------+-----------+------------------------+------------+---------+---------+
| participant | time (ms) | mod_overhead_time (ms) | vs_slowest | errors | samples |
+---------------------------+-----------+------------------------+------------+---------+---------+
| Module::Load::Conditional | 40.1 | 33.7 | 1 | 2.4e-05 | 20 |
| Module::Path::More | 10 | 3.6 | 3.8 | 1.8e-05 | 20 |
| Module::Installed::Tiny | 10.2 | 3.8 | 3.92 | 8.7e-06 | 23 |
| perl -e1 (baseline) | 6.4 | 0 | 6.3 | 1.4e-05 | 21 |
+---------------------------+-----------+------------------------+------------+---------+---------+
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.